Splurd Posted July 3, 2006 Share Posted July 3, 2006 <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 More sharing options...
Chocolate570 Posted July 3, 2006 Share Posted July 3, 2006 Actually, that script works perfectly. May I ask what browser you're using? Firefox executes it fine. Link to comment Share on other sites More sharing options...
Splurd Posted July 3, 2006 Author Share Posted July 3, 2006 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 More sharing options...
molloyboy08 Posted July 3, 2006 Share Posted July 3, 2006 what browser are you using i just tested it on ie and it works without blanking it out, and nice script too Link to comment Share on other sites More sharing options...
Splurd Posted July 3, 2006 Author Share Posted July 3, 2006 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 More sharing options...
scott100 Posted July 3, 2006 Share Posted July 3, 2006 instead of innerhtml: http://javascript.internet.com/forms/addin...l-controls.html Link to comment Share on other sites More sharing options...
Splurd Posted July 4, 2006 Author Share Posted July 4, 2006 instead of innerhtml: http://javascript.internet.com/forms/addin...l-controls.html<{POST_SNAPBACK}> Doesnt that use innerhtml as well o.O? Link to comment Share on other sites More sharing options...
Chocolate570 Posted July 4, 2006 Share Posted July 4, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now