SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Dublin
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to dynamically create fields in a form using Javascript

    Hi,

    I'd like to dynamically create fields when a certain value is selected from a drop down menu.

    For example, if I select '4' from a drop down menu then I would like 4 text fields created.

    I am able to do this by using the following code:

    ***************************************************
    <form method="POST" name="count" action="whatever">
    <p><select size="1" name="Dropdown1" onchange=count.submit()>
    ***************************************************

    and then outputting the text fileds using php but is there an other way to do this?

    Doing it this way is causing me a problem because I'd like to have the drop down menu in another form with other form attributes but I can't because this drop down menu has it's own form tags.

    I hope I'm making sense! Is there a way to do tis using javascript?

  2. #2
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not 100% sure Im reading the question right. If you want the text fields on the page they are looking at you can do that with dhtml in a loop. You would have to create a "holder" div for where you want them to show up and then create and show them ........ Your only really major problem here is browser support .... I have to find the tutorial I found on it and will post it later ..... you basically have to use the DOM and create the nodes for the new text boxes...


    Now if you dont want them right on that page Im a tad at a loss...... if the client submits the form and you provide them another based on the input from the form I dont see any problems at all

  3. #3
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AH found it ......... it was quirksmode that had all the info on that.... here

    http://www.quirksmode.org/index.html?/dom/fir.html

    Ive played wit it and have used some of the ideas on an intranet application but am a tad hesitant about using it on the web because of browser support..

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Dublin
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I'll give it a go.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •