Dynamically Create Input Box on Client Side

C

crjunk

I'm trying to find a way to create input boxes dynamically on the
client side but everything that I've come across works with IE, but not
FireFox.

On my web page, I have the following input boxes:
txtAddress1, txtCity1,txtState1, txtZip1

What I'd like to do is to have a button that says "Add Another
Location". When the user clicks on the button, then txtAddress2,
txtCity2, txtState2, and txtZip2 are created below the first location
input boxes. The user should be able to enter an unlimited number of
locations (within reason) to the web page.

Is this possible with JavaScript?

Thanks,
CR Junk
 
W

web.dev

crjunk said:
I'm trying to find a way to create input boxes dynamically on the
client side but everything that I've come across works with IE, but not
FireFox.

On my web page, I have the following input boxes:
txtAddress1, txtCity1,txtState1, txtZip1

What I'd like to do is to have a button that says "Add Another
Location". When the user clicks on the button, then txtAddress2,
txtCity2, txtState2, and txtZip2 are created below the first location
input boxes. The user should be able to enter an unlimited number of
locations (within reason) to the web page.

Is this possible with JavaScript?

Yes.

Mainly, there are two things you should know how to use. You should go
look up the following:

document.createElement()
appendChild()

For example, I'll create one html input element with the name
txtAddress2 for you:

var input = document.createElement("input");
input.type = "text";
input.name = "txtAddress2";

var elem = document.getElementById("container");
elem.appendChild(input);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top