[Javascript] Which submit caused the event?

Hassan Schroeder hassan at webtuitive.com
Tue Jan 1 15:22:07 CST 2013


On 1/1/13 1:03 PM, Tedd Sperling wrote:

> I'm not trying to be a smart-ass, but have you tried it?

Yes, of course :-)

> Here's how you can prove your assertion -- write a script that simply shows which input submit (as shown above) was clicked via an alert. It should be simple enough, but I've spent a couple of days trying to do it and believe me I've tried event.target as well as a couple hundred other combinations of ambiguous javascript terms INCLUDING jQuery's answer to all of this, which doesn't work for me either.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
document.onclick=function(e){
   var ev = window.event || e;
   alert(ev.target.name);
}
</script>
</head>
<body>

<form action="" method="post" name="myform" onsubmit="javascript:return 
false;" >
    <input type="submit" name="edit" value="Edit">
    <input type="submit" name="save" value="Save">
    <input type="submit" name="cancel" value="Cancel">
</form>

</body>
</html>


-- 
:about => about.me/hassanschroeder
:email  => hassan at webtuitive.com
:twitter => @hassan
:voice  => +1 408-621-3445


More information about the Javascript mailing list