W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2001

inserting javascript into an element

From: alex <shortestpath@yahoo.com>
Date: Thu, 6 Dec 2001 09:54:37 -0800 (PST)
Message-ID: <20011206175437.9509.qmail@web14505.mail.yahoo.com>
To: www-dom@w3.org
Can someone tell me if it's possible to
insert javascript code as an element's
attribute's value?

That is, I create a select element; I also create 
some option elements, appending each one as a child 
to the select element as I create them.

To the select element, I add an attribute 
called "onchange", and it's value is:
"alert('option changed')"; that is, I do:

var e = document.createElement("select");
e.setAttribute("onchange", "alert('option changed')");


I bring up the page on my browser, I do see
the pulldown, but when I change the option,
I don't get the javascript alert like I expect
to.

Am I doing this correctly? If not how can I 
do this?

Thanks!
-alex

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com
Received on Thursday, 6 December 2001 12:54:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:55 GMT