If the same JavaScript function is called from multiple onClick events, how can I find out which button called it?

Jayesh Nazre

Well pass a this parameter to the function being called then inside that function u can find out which button was clicked. Here is a sample piece of code.


<html>
<head>
<script language="javascript">
function test(p_this) {
	if (p_this.name == "b_1") {
		alert ("HI U clicked 1");
	} else if (p_this.name == "b_2") {
		alert ("HI U clicked 2");
	}

}
</script>
</head>
<body>
<form name=frm_test id=frm_test>
<input type=button name=b_1 
  id=b_1 Value=Button1 onclick="test(this)">
<input type=button name=b_2 
  id=b_2 Value=Button2 onclick="test(this)">
</form>
</body>
</html>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact