0
  <script type="text/javascript">
        setInterval(function(){
            $("#reg_id").focus();           
        }, 1000);
    </script>

how to disable focus if dialog is opened

setInterval(function(){
     if($("#dialogadd_participant").dialog("isOpen")){}
     else {
         $("#reg_id").focus();
     }
}, 1000);

isn't work, please help

3 Answers3

2

Use the .blur() function to remove the focus, like this:

setInterval(function(){
     if($("#dialogadd_participant").dialog("isOpen")){
         $("#reg_id").blur();
     }
     else {
         $("#reg_id").focus();
     }
}, 1000);
Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
0

You could just shift focus from #reg_id to another object like #dialogadd_participant by calling either

 $(this).focus() // within the .dialog({...}) section

or

 $('#dialogadd_participant').focus() // after the model is opened
Robin
  • 132
  • 7
0

Assign your setInterval function to a variable and then you can use clearInterval to stop focus.

var interval = setInterval(function(){
        $("#reg_id").focus();           
    }, 1000);

 if($("#dialogadd_participant").dialog("isOpen")){
    clearInterval(interval);
    $("#reg_id").blur(); 
   }
 else {
     $("#reg_id").focus();
 }

I do not understand your actual reason why you are using setInterval() but using this clearInterval() you can clear calling $("#reg_id").focus(); over and over again.

Vinit Chouhan
  • 686
  • 1
  • 10
  • 23