imarockstar Posted December 21, 2009 Share Posted December 21, 2009 I have a script that I can add a text box when a user clicks ADD .. <script type="text/javascript"> var intTextBox=0; //FUNCTION TO ADD TEXT BOX ELEMENT function addElement() { intTextBox = intTextBox + 1; var contentID = document.getElementById('contentx'); var newTBDiv = document.createElement('div'); newTBDiv.setAttribute('id','strText'+intTextBox); newTBDiv.innerHTML = "Text "+intTextBox+": <input type='text' name='jobreq' id='" + intTextBox + "' name='" + intTextBox + "'/>"; contentID.appendChild(newTBDiv); } //FUNCTION TO REMOVE TEXT BOX ELEMENT function removeElement() { if(intTextBox != 0) { var contentID = document.getElementById('contentx'); contentID.removeChild(document.getElementById('strText'+intTextBox)); intTextBox = intTextBox-1; } } </script> <p><a href="javascript:addElement();" >Add</a> <a href="javascript:removeElement();" >Remove</a></p> <div id="contentx"></div> this works great .. but I need to ad "+ 1" to each box added ... example ... for everytime a user clicks on ADD i need it to do this .. <input type='text' name='jobreq' id='" + intTextBox + "' name='" + intTextBox + "'/> user clicks ADD again <input type='text' name='jobreq2' id='" + intTextBox + "' name='" + intTextBox + "'/> <input type='text' name='jobreq3' id='" + intTextBox + "' name='" + intTextBox + "'/> <input type='text' name='jobreq4' id='" + intTextBox + "' name='" + intTextBox + "'/> <input type='text' name='jobreq5' id='" + intTextBox + "' name='" + intTextBox + "'/> so each time the user clicks add, we want to add one to the NAME tag: name='jobreq" .. can anyone help me with this ? thanks bobby Quote Link to comment https://forums.phpfreaks.com/topic/185924-adding-numbers-to-a-function-that-increase-when-i-add-a-box/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.