dcsimg
Results 1 to 3 of 3

Thread: Strange problems with browser rendering javascript [VS 2010]

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    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

    Parksie

  2. #2

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    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.
    Last edited by venerable bede; Jan 7th, 2016 at 08:44 AM.

    Parksie

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,606

    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.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width