Jump to content

adding numbers to a function ... that increase ... when i add a box


imarockstar

Recommended Posts

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

 

 

 

 

 

 

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.