From a database, I have a form that shows a list of items. These items have an order number that I can change on this form . I like to make a very simple button, that just adds +1 to the current values in the fields. The form fields are all named the same, "OrderNo" and let's call the form "MyForm", and the fields contain a number. In total there's about 20 input fields (all "OrderNo"), but it can sometimes be more or less. So in simple: A 1-click button, that adds "1" to ALL the field values. It sounds simple (and I think it has to be??), but cannot seem to figure it out. Anyone a suggestion on this? Thanks in advance!
use the dom to loop through the form fields and check the field name for the text you want. If it's there, increment the value for that field by one.
<form name="myform"> <input type="text" name="OrderNo" value="1" /> <input type="text" name="OrderNo" value="12" /> <input type="text" name="OrderNo" value="3" /> <input type="button" id="BtnAddOne" value="+1" /> </form> <script type="text/javascript"> var myTxts = document.getElementsByName("OrderNo"); document.getElementById("BtnAddOne").onclick = function() { for(var i=0;i<myTxts.length;i++) myTxts[i].value = parseInt(myTxts[i].value) + 1; } </script> Code (markup):