Skip to content Skip to sidebar Skip to footer

Set A Focus On Input Field After Alert In Javascript Error

I want to set focus on a specific input field using JavaScript function. Here is the coding: It just focuses, but I need alert and then focus on the input field. Update The code

Solution 1:

From comments below your question:

no im not using any plugin

So that is the problem. I guess you just pasted some code from somewhere and did not look at the dependencies.

Your code works if the jQuery-Confirm plugin is loaded. So just add the CDNs used in the below snippet.

functionchecknag() {
  var x1 = document.getElementById('tsumnag').value;
  var x2 = document.getElementById('salenugsum').value;
  if (+x1 == +x2) {
    $.alert({
      title: 'Alert!',
      content: 'Please enter item name',
      onDestroy: function() {
        // here the button key 'hey' will be used as the text.
        $('#munshi_perc').focus();
      }
    });
    returnfalse;
  }
}
<linkhref="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.css" /><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script><inputrequiredclass="urdu"onfocusout='checknag();'value=""type="text" /><inputrequiredclass="urdu"id="tsumnag"value=""type="text" /><inputrequiredclass="urdu"id="salenugsum"value=""type="text" /><inputrequiredclass="urdu"id="munshi_perc"value=""type="text" />

Post a Comment for "Set A Focus On Input Field After Alert In Javascript Error"