Reputation: 22
When I select any option in list then it should print its value in textbox(all html).
I tried
stafflist.setAttribute("onchange", "javacript:document.getElementById('id_17_enrolpassword').value = this.value;");
Its working in IE8+ and all modern browsers but not in IE7.
Also tried
stafflist.addEventListener('onchange',"javacript:document.getElementById('id_17_enrolpassword').value = this.value;",false);
So what changes I should do here?
Upvotes: 0
Views: 319
Reputation: 9924
I know this doesn't truly answer the question at hand, but, can't you use something like jQuery to code these sort of even handlings?
The code is a bit more readable (IMHO), and you don't have to deal this these cross-browser scripting issues yourself.
Upvotes: 0
Reputation: 178422
1) the javascript: label is only needed if the first script on the page is vbscript.
2) does this work better?
document.getElementById('stafflist').onchange=function(){
document.getElementById('id_17_enrolpassword').value = this.value;
}
?
Upvotes: 0
Reputation: 4431
IE only fires the onchange
event when the element loses focus - if you were to click outside the element or tab to a different element it should fire then.
You can get around this by using a different even, for example onkeypress
Upvotes: 1
Reputation: 8634
do it this way -
stafflist.onchange = function(){
document.getElementById('id_17_enrolpassword').value= this.value;
}
Upvotes: 0