Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select onchange event doesn't fire

Status
Not open for further replies.

tomih

Programmer
Sep 23, 2003
13
SI
Hi!

I have a problem when I programaticaly define onchange event to select tag.

the working code looks like this:
Code:
var d = document;
//create select element
var tmp = &quot;<select id='selectID' onchange='alert()'>&quot;;
var s = d.createElement(tmp);
//append select element to a div on page
div.appendChild(s);

non-working code:
Code:
var d = document;
//create select element
var tmp = &quot;<select id='selectID'>&quot;;
var s = d.createElement(tmp);
//append select element to a div on page
div.appendChild(s);
selectID.onchange = &quot;alert()&quot;;
//or
s.onchange = &quot;alert()&quot;;
//or
s.onchange = function {alert()};

I need to define onchange event programmaticaly.

I use IE 6.

Can anybody help,
thnx,
T.

Tomi Hrovatin
 
Slight adaptation of your code:
Code:
window.onload = function() {

  var d = document;
  var div = document.getElementsByTagName(&quot;div&quot;)[0];

  //create select element
  var tmp = &quot;<select id='selectID'>&quot;;
  var s = d.createElement(tmp);

  //append select element to a div on page
  div.appendChild(s);
  s.onblur = function() {
    alert('test');
  };

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top