views:

27

answers:

3

I want to have all input elements on my page trigger a function when they change. Can I do it from a CSS?

I tried this:

<STYLE type="text/css">
   input {onChange: function() {alert("foo");};}
</STYLE>

It didn't work in Google Chrome.

+2  A: 

CSS doesn't provide eventing. If this is what you want, then I would write a JavaScript function that runs when the page loads. In the function, traverse the form elements for everything that has the tagName input. For each of those, add an event handler.

Gabriel McAdams
+1  A: 

No you can't that is against the very nature of CSS. The only thing close are Pseudo-Classes like :focus :hover ect, but even they only allow to apply a different Style. So no, you can't just write JS in a CSS File and call it CSS :)

Hannes
A: 

No you can't. About the error in google chrome, use onblur. refer to the following post for more info:
http://www.google.com/support/forum/p/Chrome/thread?tid=5480bd096a668f1e&amp;hl=en

Kamyar