View Full Version : adding fields to form onclick
01-24-2005, 10:21 AM
I'm trying to make a form where, when a button is clicked, it adds another field for data entry. I need this to work with IE and Firefox. As it seems innerHTML works with firefox, my first instinct was to try that, however it reacts a bit differently in firefox (it clears previous fields when a new field is added.)
form1.innerHTML += "<input type='text'><br>";
<button onclick="addrow()">Add Row</button>
Anyhoo... it doesn't have to be innerHTML, either... just has to work with IE and FF. What is a good way to do this?
01-24-2005, 11:35 AM
Something like this should work...
var div = document.createElement ('DIV');
var input = document.createElement ('INPUT');
input.type = 'text';
<form id="form1" style="border:1px solid black">
<button onclick="addrow(this)">Add Row</button>
BTW: What's your button doing outside of the form tags??
01-24-2005, 11:14 PM
your code (above) (http://www.technosquid.com/externaljunk/mffsux.htm)
doesn't seem to work in firefox.
01-24-2005, 11:47 PM
Yes it does. The form is being submitted and so the page is reloading.
01-24-2005, 11:50 PM
Thats because your button is acting like a submit and trying to submit the form... I merely offered a script using the little information you provided as an example... It was not and is not my intention to create an entire form for you, particularly since I am not privy to all of your requirements... Change your <button... to <input type="button" and it will work as intended...
Did you note my original question of why that button was outside of your form tag... And what about a name or id??
I'm out of here...
01-24-2005, 11:55 PM
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.