locked
Multiple Select box with same name problem RRS feed

  • Question

  • Hi I have three select options with same name  as below

     

    1)
    <select name="Source" size="1" value="" onchange="function"class="input">
    <option value="">-- Select --</option>
    ....
    </select>

    3)
    <select name="Source" size="1" value="" onchange="function"class="input">
    <option value="">-- Select --</option>
    ....
    </select>


    3)
    <select name="Source" size="1" value="" onchange="function"class="input">
    <option value="">-- Select --</option>
    ....
    </select>

    Unfortunately I cannot change the name. I need to know, when a user is clicked on a select option which one is clicked? Whether it is the first select box or second or third.

     

    Any help will be highly appreciated.

    Saturday, June 7, 2008 9:46 AM

All replies

  •  

    There are number of approaches but my prefered is like this:-

     

     

    <select onchange="cbo_onchange.apply(this, arguments)" ...>

     

     

    In JavaScript code :-

     

    function cbo_onchange(ev)

    {

    alert(this.value)

    // this is the select box

    }

     

    Note ev is undefined in IE but is the mozilla equivalent to the event gobal variable in browsers such as mozilla.

     

    If IE is your only target then event.srcElement would also retrieve the select element on which the event occured.

    Monday, June 9, 2008 8:39 AM