views:

65

answers:

3

Hi all,

I'm just curious if there is a simple way to do this, something along these lines

javascript:

if(document.getElementById('button').clicked == true)
{
   alert("button was clicked");
}

html:

<input id="button" type="submit" name="button" value="enter"/>

Thank You Ruth

+2  A: 

You can add a click event handler for this:

document.getElementById('button').onclick = function() {
   alert("button was clicked");
}​;​

This will alert when it's clicked, if you want to track it for later, just set a variable to true in that function instead of alerting, or variable++ if you want to count the number of clicks, whatever your ultimate use is. You can see an example here.

Nick Craver
+1  A: 

Just hook up the onclick event:

<input id="button" type="submit" name="button" value="enter" onclick="myFunction();"/>
Paolo
Please don't use in-line handlers, [there are so many reasons not to do this](http://stackoverflow.com/questions/2479557/why-is-it-bad-practice-to-use-links-with-the-javascript-protocol/2479582#2479582).
Nick Craver
A: 

No, Javascript doesn't work in that way.Instead You can write the functionality when a button is clicked as suggested by paolo and Nick.

Srinivas Reddy Thatiparthy