tags:

views:

15

answers:

1

This doesn't work with IE7. Does anybody know a work around?

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes" onclick="alert(1);">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

When I pick Mercedes, i can see the alert box. It doesn't happen in IE.

+1  A: 

Try this

<select onclick="myalert(this.value)">
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>
<script>
   function myalert(value) {
     switch(value) {
       case "mercedes":
          alert(1);
          break;
       }
   }
</script>
John Hartsock
Yup, i had to attach the event to the select.
FALCONSEYE