T
Thiago Jorge
Hello Everyone!
I am trying to implement a form which some of the fields I have are
required.
In order to do that I am using the onBlur function, so when I either
click on a different field, or Tab out to the next field, it should
check if my last entry was not blank, and in case it was, it should
return to that field until the user enters a valid entry.
Here is my code:
-------------------------------------------------------------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkInput(element,curentField) {
if (element.value == "" ) {
document.form1[curentField].focus();
alert("All fields with * are required!");
}
}
// -->
</SCRIPT>
<form name="form1" method="post" action="">
<INPUT TYPE="text" NAME="Name" VALUE="" size="17"
onBlur="checkInput(this,'Name')">
<input type="submit" name="Submit" value="Submit">
</form>
-------------------------------------------------------------------------------------
The problem I am having is, when I use the Tab to move to the next
field, the alert message pops up 6 times. If I click on some other
field or on the background using the mouse, then the alert message
shows up only once, like it should!
Any idea why the Tab causes 6 alerts and how can I do to change that?
Thanks,
Thiago
I am trying to implement a form which some of the fields I have are
required.
In order to do that I am using the onBlur function, so when I either
click on a different field, or Tab out to the next field, it should
check if my last entry was not blank, and in case it was, it should
return to that field until the user enters a valid entry.
Here is my code:
-------------------------------------------------------------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkInput(element,curentField) {
if (element.value == "" ) {
document.form1[curentField].focus();
alert("All fields with * are required!");
}
}
// -->
</SCRIPT>
<form name="form1" method="post" action="">
<INPUT TYPE="text" NAME="Name" VALUE="" size="17"
onBlur="checkInput(this,'Name')">
<input type="submit" name="Submit" value="Submit">
</form>
-------------------------------------------------------------------------------------
The problem I am having is, when I use the Tab to move to the next
field, the alert message pops up 6 times. If I click on some other
field or on the background using the mouse, then the alert message
shows up only once, like it should!
Any idea why the Tab causes 6 alerts and how can I do to change that?
Thanks,
Thiago