Reputation: 11
I have put a simple eventhanlder
for my button click and passed two arguments upon clicking it. Hi is undefined error is throwing. If i put "Hi" (in double quotes) the event handler is doesnt fire at all. May i know what needs to be addressed.
I need this exactly as in my requirement I have to pass something like <%#(string)DataBinder.Eval(Container, "DataItem.Category")%>
when a repeater row is clicked.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script type ="text/javascript" language = "javascript">
function OnClickeHandler(i, j) {
debugger;
}
</script>
<form id="form1" runat="server">
<div>
<input type ="button" id = "myButton" value = "Click" onclick = "OnClickeHandler(1,Hi)" />
</div>
</form>
</body>
</html>
Upvotes: 1
Views: 567
Reputation: 31
Use single quotes to pass hi as string
Onclick="OnClickeHandler(1,'Hi')"
In HTML when you write any attributes you cover them with single quote of double quite
Like following both are valid.
onclick="abc()"
onclick='abc()'
JavaScript can cover sting by both single quote or double quote and you also need to make sure that why passing string you don't break html.
All following are valid
onclick="abc('xyz')"
onclick='abc("xyz")'
onclick="abc('x\'yz')" ------ passing ' as string
onclick='abc("xy\"z")' ------ passing " as string
You just need to make sure that what ever quote you are using to cover html attribute you don't use that in function call or value of attribute.
Upvotes: 1
Reputation: 6615
you need to put Hi in single quotes : 'Hi', as the call to the function is already in double quotes
Upvotes: 1