I have a simple text field that looks like this.
<asp:TextBox ID="txtMyTextBox" runat="server" onblur="checkMyText()" ></asp:TextBox>
At the top of my page, I have this little bit of JS
<script type="text/javascript">
function checkMyText() {
var args = document.getElementById('<% =txtMyTextBox.ClientId %>').value;
alert(args);
}
</script>
This works fine. When I try to do this.
<asp:TextBox ID="txtMyTextBox" runat="server" onblur="checkMyText("txtMyTextBox")" ></asp:TextBox>
. . .
function checkMyText(ElementID) {
var args = document.getElementById('<% =ElementID.ClientId %>').value;
alert(args)
}
It fails.
I am entirely new to javascript, so I am not sure how it handles passing variables or treating them inside strings. The idea is if I add an: ID="txtMyOtherTextBox" I only need to call onblur="checkMyText("txtMyOtherTextBox")" for that button. How do I javascript strings?