Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enter key start onblur event and not onkeyup/onkeydown

    On my web I display configuration info, that user can edit, in a table.
    The correct user behavior should be to press Enter key after editing the field in order to set the changes.
    If he "leaves" the field without pressing Enter- the changes will be dismiss.
    In order to do that- I use "onkeyup" and "onblur"

    "onkeyup"
    (1) set a flag that field's content has been changed
    (2) if the key is Enter (==13) , it sends the server a set request with the current value
    (*) also tried "onkeypress" or "onkeydown"

    "onblur" - check the flag if the field's content has been changed. if so- send a refresh request to server that re-send current saved data (and erase user's changes).

    I recently noticed that while it works great in Chrome, on Explorer pressing the Enter key sets both events, and sometimes only the "onblur" event, thus ignores user's requests....

    Do you have any idea how to deal with it?

    THANKS!!!!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    onblur seems to have quirks in IE. Try this instead:-


    Code:
    <input type = "text" id = "textfield" size = "20"  onkeyup = "chk(event)";>
    
    <script type = "text/javascript">
    
    document.getElementById("textfield").onchange = function() {
    alert ("Field content has changed");
    }
    
    function chk(ev) {
    var key;
    ev = ev || event;
    key = ev.keyCode;
    alert (key);  // for testing
    if (key == 13) {
    var val = document.getElementById("textfield").value;
    alert ("You pressed the Enter key\nYou have entered " + val);
    return false;
    }
    }
    
    </script>

    Quizmaster: Name the 4th state of the USA to join the Union. It was named after a British king.
    Contestant: Texas.
    Last edited by Philip M; 07-18-2012 at 10:17 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did something similar:
    (I also tried to replace onBlur with onChange - did not work)

    Code:
    			
    <!-- Line LO freq -->
    <tr>
    <td><div id=div_lof_a><a href="manual.html#lof_mod" target="_blank">BUC LO Freq</a></div></td>
    <td><div id=div_lof_select><input id="lof" value="" onkeyup="set_is_unsaved_change();if ((event.keyCode==13) && (div_img_no_touch.className=='no_touch_hide') && (is_positive_num(this))) {div_img_long_action.className='wait_img_show';div_img_no_touch.className='no_touch_show';updateStatusParams('query.fcgi','form_state=2&form_name=line_mod&field_name=lof&field_val='+this.value);reset_is_unsaved_change();}" onblur="if(is_set_unsaved_change()) {reset_is_unsaved_change();updateStatusParams('query.fcgi','form_state=1&form_name=line_mod');}"></div></td>
    </tr>


  •  

    Posting Permissions

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