<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
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);
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
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.