Вопрос

When I select any option in list then it should print its value in textbox(all html).

enter image description here

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?

Это было полезно?

Решение

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;
}

?

Другие советы

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

do it this way -

stafflist.onchange = function(){
   document.getElementById('id_17_enrolpassword').value= this.value;
}

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top