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

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


Do You Yahoo!?
Send your FREE holiday greetings online!
Received on Thursday, 6 December 2001 12:54:38 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:09 UTC