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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    600
    Thanks
    17
    Thanked 0 Times in 0 Posts

    onClick Working in FF, but not IE

    Hey Guys,

    I'm having a problem with the following form option:

    Code:
    <select name="group" class="textbox">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3" onClick="alert('hello world')">3</option>
    </select>
    It works in Firefox, but doesn't work in IE. What am I doing wrong here? I need a particular function to be called when a specific option is selected within a SELECT, and in IE, it does nothing.

    Any suggestions would be greatly appreciated.

    Thanks!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Options can't have event handlers. You need to use onchange in the select with a combination of an if statement
    Code:
    <select name="group" class="textbox" onchange="if(this.options[this.options.selectedIndex].value == '3') alert('hello world')">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Will this work?
    Code:
    <script type="text/javascript">
    function groupChanged(select)
    {
        switch(select.options[select.selectedIndex].value)
        {
            case '3':
                alert('hello world');
                break;
        }
    }
    </script>
    
    <select name="group" class="textbox" onchange="groupChanged(this)">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Posts
    600
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Thanks guys. Aero's worked and did what I need it to do.

    Thanks again.


  •  

    Posting Permissions

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