How to get the id of a checkbox control on javascript

Posted by mohammedr88-18313 under ASP.NET on 5/6/2014 | Points: 10 | Views : 665 | Status : [Member] | Replies : 2
hi all


How to get the id of a checkbox control on javascript alert box


function GetId(sender, e) {
try {
var Leve1 = e.get_id();
alert(Leve1);
}
catch (e) {
alert("error"+e.message);
}

}





<asp:CheckBox ID="chkbx1" runat="server" OnClick="return GetId(this);" Font-Size="XX-Small" />



regards
Mohammed Rafi




Responses

Posted by: A2H on: 5/6/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
Change your code like given below
 <script type="text/javascript">
function GetId(obj) {
//Get the ID value
var Leve1 = obj.id;
//Show the alert message
alert(Leve1);
}
</script>


Complete Code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function GetId(obj) {
//Get the ID value
var Leve1 = obj.id;
//Show the alert message
alert(Leve1);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="chkbx1" runat="server" OnClick="return GetId(this);" Font-Size="XX-Small" />
</form>
</body>
</html>


Thanks,
A2H
My Blog

mohammedr88-18313, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: mohammedr88-18313 on: 5/6/2014 [Member] Starter | Points: 25

Up
0
Down
Thanks its working fine

mohammedr88-18313, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response