onblur call issue

M

Mahesh

Hi all,

Can any one advice what can be a work around here?
When i run the code below, its showing the alert msg twice onfocus out
of tf1

Thanks in advance,
Maheshkumar

<html>
<script type="text/javascript">

function setFocus(ref) {
globalTakeFocus=ref;
setTimeout("globalTakeFocus.focus();globalTakeFocus.select()",100);
}

function checkfun()
{
if(document.getElementById("tf1").value=="")
{
//document.getElementById("tf1").focus();
alert("The field is empty");
setFocus(document.getElementById("tf1"));
return;
}

if(document.getElementById("tf2").value=="")
{
//document.getElementById("tf2").focus();
alert("The field is empty");
setFocus(document.getElementById("tf2"));
return;
}
}

</script>
<body>
<table>
<form>
<tr> <td>
TF1: <input id="tf1" type="text" value="" onblur="checkfun();"/></td>
</tr>
<tr><td>
TF2: <input id="tf2" type="text" value="tf2" onblur="checkfun()"/></
td>
</tr>
</form>
</table>
</body>
</html>
 
M

marss

Mahesh said:
Hi all,

Can any one advice what can be a work around here?
When i run the code below, its showing the alert msg twice onfocus out
of tf1

Sequence of the events:
1.tf1 lost focus.
2.tf2 got focus.
3.alert that was caused by tf1 onblur event is shown up (tf2 lost
focus).
4.alert that was caused by tf2 onblur event is shown up.
5.tf1 got focus.

You can avoid it in this way:

function checkfun(sender)
{
if(sender.value=="")
{
alert("The field is empty");
setFocus(sender);
}
}

TF1: <input id="tf1" type="text" value="" onblur="checkfun(this)"/>
TF2: <input id="tf2" type="text" value="tf2" onblur="checkfun(this)"/>

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top