Thread: dynamic fields

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Ashburn, VA, US
    Posts
    1
    Rep Power
    0
    How do I use javascript to dynamically show form fields when a selection has been made from a drop-down menu? The fields can be one or many select boxes, radio boxes, text boxes, etc.
    Is this possible?
    Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Helden,Limburg,The Netherlands
    Posts
    33
    Rep Power
    15
    If you do not want to reload the page you can use select menus. If someone makes a choice in one list the other lists adjust accordingly. This is possible because you can dynamically add, remove or edit options in a select list by using JavaScript. There are a lot of tutorials available on-line that can help you with this. Probably Devshed has a tutorial on this topic.

    If you want to visually adjust other form elements you have to reload your page, with some additional parameters or use a frameset to have the intial choice in one frame and the rest of the form in another one. .

    ------------------
    Ramon Litjens
    Boradoli Web Design
    (www.boradoli.nl)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Aalborg, Denmark
    Posts
    36
    Rep Power
    15
    Lets say you have a form named myForm and in that form you have a drop down menu as follows
    <select name="mySelect">
    <option value="value1">value1</option>
    <option value="value2">value2 plus some text</option>
    <option value="value3">value3</option>
    </select>

    and you have a field you want the selcted copied to:
    <input type="text" name="myField">

    you the make a small script (remember to place it between the <head></head>-tags for good styles sake)

    <script language="javascript" type="text/javascript">
    function myFunction(theForm) {
    theForm.myField.value = theForm.mySelect.value;
    }
    </script>

    now all you need to do is to make the dropdown call the function. You do that by adding a bit of code to the <select>-tag:

    <select name="mySelect" onChange="myFunction(this.form)">

    You can also call it using onKeyUp, onkeypress etc.

    // Martin
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    10
    Rep Power
    0
    I had the same problem.
    What I resorted to was executing a new cgi
    script when the change event occured.
    The cgi script then determined the contents
    of the new page and re-sent them.
    This method saves having to have multiple
    html pages that are all similar.

Similar Threads

  1. Updating text fields from dynamic SQL select box?
    By Trent Hatred in forum HTML Programming
    Replies: 3
    Last Post: February 6th, 2004, 10:34 AM
  2. Replies: 2
    Last Post: January 28th, 2004, 07:07 AM
  3. Dynamic form fields
    By phidoux in forum HTML Programming
    Replies: 2
    Last Post: November 12th, 2003, 01:42 PM
  4. dynamic hidden form fields
    By nbsp in forum PHP Development
    Replies: 5
    Last Post: October 10th, 2003, 12:51 PM
  5. dynamic text fields and eval
    By blatant in forum Flash Help
    Replies: 2
    Last Post: September 1st, 2003, 09:55 PM

IMN logo majestic logo threadwatch logo seochat tools logo