View Full Version : Create new fields via onClick

09-18-2005, 04:07 AM
Im trying to create a new field when the user presses a button.

The thing is, I dont want the page to reload and lose data previously entered into other fields.

Also, I want the name of the field to have a number which increments by 1 each time this button is pressed.

For example,
The button is there and when its click, a field called field1 is created. If the button is clicked again, another field is created called field2. and so on.

Thanks in advance :p

09-18-2005, 04:23 AM
Do a google for createElement(), should get you started...

Good luck

09-18-2005, 04:29 AM
Awesome. I think I got it now...

Thanks champ :)

09-18-2005, 04:53 AM
function addField(){
newField = document.createElement("text");
newField.value= "This is the new field";

<form name="myForm\">
<input type="button" value=\"Add new field" onClick="addField();">

I cant seem to get it to create the new field... What am I doing wrong?

09-18-2005, 05:07 AM
Theres no element called "text", I believe you wanted "input".
newField = document.createElement("INPUT");
Also, the slashe here:
<form name="myForm\">
Needs to be removed.

Good luck;

09-18-2005, 05:09 AM
Awesome! It works Yay!

Thankyou so much.

Yeah the slash was there because Im using it in amongst php.

09-18-2005, 05:11 AM
You're welcome :)