开发者

Fire onchange for combo box programatically using javascript in IE not working

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开发者_StackOverflow another method.

Please help... Thanks


<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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜