select box name question

Discussion in 'JavaScript' started by jj0914, Aug 23, 2007.

  1. #1
    I have a dynamic select box, the way it works is that the appearance of next select box will depend on the selection of previous select box. It is working perfectly for me.
    My problem is I want to make the name of each select box like this:

    name of second select box is "<select name=Level_1",

    third select box is children of second, so the name is: "<select name=Level_2"

    forth select box is children of third, so the name is: "<select name=Level_3"

    ...

    I am not sure how I can achieve that, can anyone give me a hint? thanks in advance
     
    jj0914, Aug 23, 2007 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    from what i get out of your question my suggestion is to give each select an ID - say, 1,2,3,4

    than when you add on onchange with whatever function
    <select id="1" onchange="somefunction(this.id)">

    i think you could probably than change the names with

    function somefunction(someID)
    {
    if (someID == 1) //When the change comes from the first select
    if (document.getElementById("1").selectedIndex == 1)
    document.getElementById("2").name = "someNewName"
    else if (document.getElementById("1").selectedIndex == 2)
    document.getElementById("2").name = "someNewName"
    }

    that's a lot of hardcoded if statements though, i'm sure there are ways to cut down on code depending on what you're actually trying to do
     
    Jamie18, Aug 23, 2007 IP
  3. jj0914

    jj0914 Guest

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the id of my select is not in order, e.g current one can be 10, next one can be 389, I don't think assigning static id is useful.
     
    jj0914, Aug 24, 2007 IP