5
Colleagues.
I’m trying to put two functions inside the onchange, but the functions only work when shooting one or the other.
onchange="soma(); alterar();"
How could I fix this?
Thank you!
5
Colleagues.
I’m trying to put two functions inside the onchange, but the functions only work when shooting one or the other.
onchange="soma(); alterar();"
How could I fix this?
Thank you!
14
The best way would be to use .addEventListener
thus
el.addEventListener('change', soma);
el.addEventListener('change', alterar);
Another option would be to pass a function that calls both:
onchange="processar();"
and
function processar(){
soma();
alterar();
}
If these two functions have common logic it would be better to have one call to the other.
Another option is to put all actions separated by commas for Javascript to run all:
onchange="(soma(), alterar());"
Example:
Clica aqui:
<input type="checkbox" onChange="(alert(1), alert(2));">
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Thank you Sergio.
– user24136
In older versions of IE the
addEventListener
does not work, has to use theattachEvent
. TheattachEvent
expects events with the prefixon
. Suggestion:if (el.attachEvent) { el.attachEvent("onchange", foo, true); } else { el.addEventListener("change", foo); }
– MFedatto