Freexel
Freexel

Reputation: 53

Getting values with javascript position()

My shopping cart script is intended to check if an article is already in the shopping cart; then the numbers must be filled in the survey.

I work with Javascript. I give the ID number through a position() function.

This is a part of the script where I pick list:

<input type="text" size="2" name="aantalArts_{position()}" id="aantalArts_{position()}"/>

The output:

<input type="text" size="2" value="" name="aantalArts_1" id="test" class="infoButton">
<input type="text" size="2" value="" name="aantalArts_2" id="test" class="infoButton">
<input type="text" size="2" value="" name="aantalArts_3" id="test" class="infoButton">
<input type="text" size="2" value="" name="aantalArts_4" id="test" class="infoButton">

I am just filling the numbers, but how do I deal with the positions?

<script language="javascript" type="text/javascript">
    if(document.all.artNr.value = <%=artNrWW%>);{
        document.all.aantalArts_??????.value = <%=aantalWW%>;
    }
</script>

Upvotes: 2

Views: 128

Answers (1)

Domenic
Domenic

Reputation: 112917

You are probably looking for the following syntax:

var i = 1; // or whichever
document.all["aantalArts_" + i].value = <% aantalWW %>;

Upvotes: 1

Related Questions