1

I want to call onchange function dynamically when user change value of another combo box. My code is as under :

HTML

<select name="vbitratecontrol0" id="combo1" onchange="set()">;
      <option value="0">None</option>
      <option value="1">A</option>
      <option value="2">B</option>
  </select>

Javascript

function fun(){
      document.getElementById(combo1).onChange();
}

when function fun is called, onchange of combo1 should be fired which is working fine in FF but not in IE6,7,8. fun I m calling from another method.

Please help... Thanks

1 Answer 1

3
<select name="vbitratecontrol0" id="combo1" onchange="set()">;
      <option value="0">None</option>
      <option value="1">A</option>
      <option value="2">B</option>
  </select>

<script>

function fireEvent(element,event){
    if (document.createEventObject){
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
    }
    else{
    // dispatch for firefox + others
    var evt = document.createEvent("Events");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
    }
}
function set(){alert("asd");}

function fun(){
      fireEvent(document.getElementById("combo1"), "change");;
}

fun();
</script>

HTH!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.