REWRITE: I have a select field with an associated onchange event.
<select id='customer' onchange='loadRate(this.value)'>
At some point in my code, I assign a value to this select field with Javascript.
document.getElementById('customer').value = "Main St Packaging";
Why does this not trigger the开发者_如何学Go onchange
event? How do I fix it so that it does? Right now I am doing it by writing explicitly:
loadRate('Main St Packaging')
but I was wondering if there is a better way?
Try calling the "onchange" method explicitly:
var el = document.getElementById('customer');
el.value = "Main St Packaging";
el.onchange(); // Will run "loadRate(this.value)", per your HTML.
精彩评论