Hi,

I have a text input that when it receives the text "RESET" and a tab,
the form should reset and the focus should go to the first text input
element. But something weird happens, instead the focus goes to the
first element (I have seen this by placing an alert in the right
place) and then ends up on the second text input. I have no idea why,
as the last 'command' is to focus on the first input element. Any
ideas. A bit of code:

$("input#serial_number").focus(function () {
  var serial_number = "";

  // Captures the tab event
  $("input#serial_number").keypress(function(event){

          // Captures the tab event and so counts as a save....
          if(event.which == 0){
                  // Get the current value
                  serial_number = $("input#serial_number").val();

                  // Check to see if the user wants to reset the form
                  if(serial_number == "RESET"){
                        // Reset the form.
                        $("form#" + form_id)[0].reset();

                        $("input[tabindex=1]").focus();
                  }
          } // end if
  });
});

I have also tried doing this using the blur event, but that did not
work either. Also, a reset button is not desirable.

Thanks
Stephen

Reply via email to