Instead of
<input type="button" value='Contact query' onclick="sendQuery"'(<%=Model.AssociatedLists[0].Id.ToString()%>)'"/>
Use
<input type="button" value='Contact query' onclick="sendQuery('<%=Model.AssociatedLists[0].Id.ToString()%>')"/>
Frage
I have a input button and onclick I want to fire a javascript function and pass my C# object property. It contains an ID which I will need with an Ajax function. I am having an issue with correctly escaping my quotes.
<td><input type="button" value='Contact query' onclick="sendQuery"'(<%=Model.AssociatedLists[0].Id.ToString()%>)'"/></td>
function sendQuery(param) {
alert(param);
}
This is how the html is formed in my browser:
<input onclick="sendQuery" type="button" '(e543cd31-7491-432e-b8a4-9718ad2c44e2)"="" value="Contact query"/>
My button doesn't fire because my HTML isn't well formed.
Any help please?
Lösung 3
Instead of
<input type="button" value='Contact query' onclick="sendQuery"'(<%=Model.AssociatedLists[0].Id.ToString()%>)'"/>
Use
<input type="button" value='Contact query' onclick="sendQuery('<%=Model.AssociatedLists[0].Id.ToString()%>')"/>
Andere Tipps
This should do the trick
onclick="sendQuery('<%=Model.AssociatedLists[0].Id.ToString()%>')"
Remove the onclick
reference, add an id on the button and try the following:
<script type="text/javascript">
$(document).ready(function () {
$('#your-button-id').click(function () {
sendQuery(<%=Model.AssociatedLists[0].Id.ToString() %>);
});
});
</script>