Hopefully someone can guide me with this, its driving me nuts!
Below is code from a little test I put together to test theory, in the real site, however, this will be looped from a database.
My problem, is that if I select, say, Option 8 from the second select box and click submit_2, the function picks up the third index from the first select box and so returns "Option3"
Expand|Select|Wrap|Line Numbers
- <script type = "text/javascript">
- function AddItem(theid) {
- var x=document.getElementById("cboProduct_" + theid).selectedIndex
- var y=document.getElementsByTagName("option")
- var code=y[x].value
- var qty = document.getElementById("txtQty_" + theid).value;
- alert(code)
- }
- </script>
- Code:<select name="cboProduct_1" id ="cboProduct_1">
- <option selected value ="None">Select an option</option>
- <option value="Option1">Option 1</option>
- <option value="Option2">Option 2</option>
- <option value="Option3">Option 3</option>
- <option value="Option4">Option 4</option>
- <option value="Option5">Option 5</option>
- </select> Qty:<input type = "text" size="5" id="txtQty_1">
- <input type="submit" value = "Add Item" onClick="AddItem('1')" name="submit_2" id="submit_2">
- <br /> <br />
- Code:<select name="cboProduct_2" id="cboProduct_2">
- <option selected value ="oneN">Select an option</option>
- <option value="Option6">Option 6</option>
- <option value="Option7">Option 7</option>
- <option value="Option8">Option 8</option>
- <option value="Option9">Option 9</option>
- <option value="Option10">Option 10</option>
- </select> Qty:
- <input type = "text" size="5" id="txtQty_2">
- <input type="submit" value = "Add Item" onClick="AddItem('2')" name="submit_2" id="submit_2">
- And so on.....
Suggestions of alternate approaches are also welcome.
Gaz.