Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] item.onclick = "alert('foo');";


  • From: judah-fc at t8design.com (Judah Frangipane)
  • Subject: [Javascript] item.onclick = "alert('foo');";
  • Date: Mon Nov 7 11:30:19 2005

Hi Anthony,

Try something like this,

var item = document.getElementById('foo');
item.onclick = function () {
 alert('foo');
}

on click in javascript may be case sensitive, ie "onClick"

the way you have it you are only passing in a string and not a reference 
to the alert function

to do it your way you have to do this

// assign onclick equal to the alert function
item.onClick = alert;
item.onClick("some value")

but since alert takes a parameter i do not know if it will work. i do 
not know if onClick passes in an evt object so you may have to stick 
with the first example i gave you.

Judah

Anthony Ettinger wrote:

>this doesn't seem to work:
>
>var item = document.getElementById('foo');
>item.onclick = "alert('foo');";
>
>http://developer.mozilla.org/en/docs/DOM:element.onclick
>
>Anthony Ettinger
>ph: (408) 656-2473
>web: http://www.apwebdesign.com
>_______________________________________________
>Javascript mailing list
>Javascript@xxxxxxxxxx
>https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>
>  
>