Jump to content

Problem with my script


Splurd

Recommended Posts

<html><head><script type="text/javascript">function addbox(){var x=document.getElementById('haha')x.innerHTML+="<hr>tb1<input type='text' name='tb1'><br>tb2<input type='text' name='tb2'><br>"}</script><title>test start</title></head><body bgcolor="white" text="black"><form action="test2.asp" method="post"><div id="haha">tb1<input type="text" name="tb1"><br>tb2<input type="text" name="tb2"><br></div><input type="button" onClick="addbox()" value="Clickzor"><input type="submit" value="lol"></form><br>content here!</body></html>

Yeah. Wonderful code. Works. Cept that every time I click the button to add more boxes, it blanks out the previous boxes.Am I doing it incorrectly? I'm new to the javascript thing. (######, still pretty new to most things too)

Link to comment
Share on other sites

uh, its like, you type in something, hit the button to add boxes, but it wipes out what you previously typed.after a moment of thought, In order to make it work, I have to loop thru the textboxes, get their value, and somehow get it print out the value inside the text boxes.

Link to comment
Share on other sites

I was using firefox and it didnt work. I dont know why, anyway I made one that worked

<html><head><script type="text/javascript">function addbox(){var x=document.getElementById('haha')//divvar y=document.getElementById('warnety')//formvar i=0for (i=0;i<(y.length-2);i++)	{	z+="tb1<input type='text' name='tb1' value=" + y.elements[i].value + "><br>"	i++	z+="tb2<input type='text' name='tb2' value=" + y.elements[i].value + "><br><hr>"	}x.innerHTML= z +"tb1<input type='text' name='tb1'><br>tb2<input type='text' name='tb2'><br>"}</script><title>test start</title></head><body bgcolor="white" text="black"><form ID="warnety"action="test2.asp" method="post"><div id="haha">tb1<input type="text" name="tb1"><br>tb2<input type="text" name="tb2"><br></div><input type="button" onClick="addbox()" value="Clickzor"><input type="submit" value="de submit buttan"></form><br></body></html>

Loops thru the form, puts the values in z, then pastes z + 2 new textboxes out.:)

Link to comment
Share on other sites

See, the problem with your script is that it uses the += operater with innerHTML. += Makes javascript rewrite the innerHTML of an element, so the form element you just typed in has been replaced. :S

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...