Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Infinte loop with onblur

Status
Not open for further replies.

BBDan

IS-IT--Management
Jul 4, 2003
10
US
Hi guys, wondering if any of you know how to break an infinite loop caused by an onblur event?

<HTML>
<HEAD>
<TITLE>Webpurchase</title>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

function checkCo()
{
if(document.form1.companyName.value==&quot;&quot;)
{
window.alert(&quot;Please enter Company Name.&quot;)
document.form1.companyName.focus()
return false
}
return true
}

function checkPerson()
{
if(document.form1.contactPerson.value==&quot;&quot;)
{
window.alert(&quot;Please enter Contact Person.&quot;)
document.form1.contactPerson.focus()
return false
}
return true
}


//-->
</script>
</head>
<BODY>

<FORM ACTION=&quot;webpurchase3.php&quot;
ID=&quot;form1&quot;
NAME=&quot;form1&quot;
METHOD=&quot;POST&quot;
// onsubmit=&quot;return checkData()&quot;
// onblur=&quot;checkCo()&quot;
// onblur=&quot;checkPerson()&quot;
>


<tr>
<td>Company Name</td>
<td align=left><INPUT TYPE=&quot;TEXT&quot; ID=&quot;companyName&quot; size=30 maxlength=30 onblur=&quot;checkCo()&quot;></td>
</tr>

<tr>
<td>Contact Person</td>
<td align=left><input type=&quot;text&quot; name=&quot;contactPerson&quot; size=30 maxlength=30 onblur=&quot;checkPerson()&quot;></td>
</tr>
 
<FORM ACTION=&quot;webpurchase3.php&quot;
ID=&quot;form1&quot;
NAME=&quot;form1&quot;
METHOD=&quot;POST&quot;
// onsubmit=&quot;return checkData()&quot;
// onblur=&quot;checkCo()&quot;
// onblur=&quot;checkPerson()&quot;
>

// is for javascript for html:
<FORM ACTION=&quot;webpurchase3.php&quot;
ID=&quot;form1&quot;
NAME=&quot;form1&quot;
METHOD=&quot;POST&quot;
<!-- onsubmit=&quot;return checkData()&quot;
onblur=&quot;checkCo()&quot;
onblur=&quot;checkPerson()&quot;-->
>


Known is handfull, Unknown is worldfull
 
Hi vbkris,

Thanks for your help. It breaks the loop, but it doesn't check my other form fields. Do you have any suggestions?

Thanks!
 
try this:
<FORM ACTION=&quot;webpurchase3.php&quot;
ID=&quot;form1&quot;
NAME=&quot;form1&quot;
METHOD=&quot;POST&quot;
onsubmit=&quot;return checkData()&quot;
<!-- onblur=&quot;checkCo()&quot;
onblur=&quot;checkPerson()&quot;-->
>


Known is handfull, Unknown is worldfull
 
Hi,

It still doesn't work, but I am now writing a whole new check sequence. Do you know, by any chance, how to check each form field one by one rather than using &quot;onsubmit&quot;

Thanks
 
that can be done but validation for all fields must be the same.....

i always check the fields one by one....


atleast does the function checkData() get called in my previous code?

Known is handfull, Unknown is worldfull
 
If you have a form where you want to validate some, or all, of the fields, create a &quot;validate&quot; function and put all of your tests in that function.

function validateForm(theForm) {

if (theForm.companyName.value.length == 0) {
alert(&quot;Please Enter A Company Name&quot;);
theForm.companyName.focus()
return (false);}

if (theForm.address.value.length == 0) {
alert(&quot;Please Enter Company Address&quot;);
theForm.address.focus()
return (false);}
.
.
.
}

In your <FORM> tag, call it like this: onSubmit=&quot;return validateForm(this)...

This way, you can pick and choose what to test, and with what values. All tests must be false before the form will submit.





There's always a better way. The fun is trying to find it!
 
Hi vbkris,

The checkdata() works with onsubmit; i guess what i am stuck with is the individual checks, so i use onblur after every entry box.

<tr>
<td>Company Name</td>
<td align=left><INPUT TYPE=&quot;TEXT&quot; ID=&quot;companyName&quot; name= &quot;companyName&quot; size=30 maxlength=30 onblur=&quot;JavaScript:checkAccess() &quot; ></td>
</tr>

<tr>
<td>Contact Person</td>
<td align=left><input type=&quot;text&quot; ID=&quot;contactPerson&quot; name=&quot;contactPerson&quot; size=30 maxlength=30 onblur=&quot;JavaScript:checkAccess()&quot; ></td>
</tr>


Well, now the loop is reiterating 2 times for some reason, but i guess i need to debug it myself. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top