Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Location
    I'm a canuck eh.
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Adding Elements to a select element on an html form, using javascript

    Ok, I'm trying to set my page up with 3 drop down lists in such a way that selecting one option in one controls what is available in the next one and so on, however, though I know how to clear a select object, I don't know how to add new elements. I am aware of the .add method but I can't figure out how to use it.
    Here's what I have so far
    function generateVersionsListForProject(proj, ver)
    {
    var x=document.getElementById(ver);
    var y=document.getElementById(proj);
    x.disabled=false;
    for (i=0;x.length>0;i++)
    {
    x.remove(0);
    }
    switch(y.selectedIndex)
    {
    case 1:
    add items;
    break;
    ...
    default:
    x.disabled=true;
    break;
    }
    }
    obviously proj is the Id of the parent select and ver is the one that is depenent on it. The first part clears the list, that much I know works.
    Not sure it matters but this script will eventually be dynamically generated by a .cgi page such that it will always clear, but then it will add different items depending on what was selected in proj. In theory this will be called in the onchange event.
    Last edited by gwarden; 04-04-2006 at 06:05 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

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