Dynamically Create Input Box on Client Side

Discussion in 'Javascript' started by crjunk, Dec 8, 2005.

  1. crjunk

    crjunk Guest

    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
     
    crjunk, Dec 8, 2005
    #1
    1. Advertising

  2. crjunk

    web.dev Guest

    crjunk wrote:
    > 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);
     
    web.dev, Dec 8, 2005
    #2
    1. Advertising

  3. crjunk

    crjunk Guest

    crjunk, Dec 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shaul Feldman
    Replies:
    0
    Views:
    871
    Shaul Feldman
    Apr 16, 2004
  2. Magnus Blomberg
    Replies:
    3
    Views:
    741
    Magnus Blomberg
    Apr 14, 2005
  3. ashutosh
    Replies:
    3
    Views:
    9,053
    Andrew Thompson
    Jun 16, 2005
  4. cjl
    Replies:
    1
    Views:
    10,549
    Michael Winter
    Oct 31, 2005
  5. cjl
    Replies:
    7
    Views:
    216
    Thomas 'PointedEars' Lahn
    Oct 30, 2005
Loading...

Share This Page