Strange problems with browser rendering javascript [VS 2010]
I have the following just before my </body>
HTML Code:
<script type="text/javascript">
//success message..
function OnSuccess(result) {
if (result) {
document.getElementById("<%= lblMessage.ClientID %>").textContent = result;
}
}
function CheckForReturnAndComplete() {
if (event.keyCode === 13) {
var txt1 = document.getElementById('<%=text1.ClientID %>').value;
var txt2 = document.getElementById('<%=text2.ClientID %>').value;
PageMethods.ScanComplete(txt1, txt2, OnSuccess, OnFailure);
}
}
</script>
My WebMethod in the code behind (cut down for simplicity) :
HTML Code:
[WebMethod]
public static string ScanComplete(string data1,string data2)
{
string returnValue = string.Empty;
returnValue = data1 + " and " + data2 + " have been saved.";
return returnValue;
}
Basically when the user hits carriage return on the second textbox 'text2' the contents of text1 and text2 are sent to the [WebMethod], concatenated and returned to be displayed in a label.
This works great on my dev machine but when I try it from any another machine the label does not appear. It's been a while since I have done any web work so am a wee bit confused.
Anyone have any ideas why this is happening?
Thanks in Advance
Re: Strange problems with browser rendering javascript [VS 2010]
Further Issues. The following code checks for a carriage return when entering in textbox1 ('text1') and shifts focus to textbox2 ('text2').
function CheckForReturn() {
if (event.keyCode === 13) {
document.getElementById('text2').focus();
}
}
This works well in IE 10/11 but in firefox does nothing at all.
It's not a huge issue though as the users will only be using IE.
Re: Strange problems with browser rendering javascript [VS 2010]
https://jsfiddle.net/tdzs93jb/3/
You need to pass the event argument into your event handler for it to work in Firefox.