Kathrynmj
asked on
Focus on empty or error field will not "stick".
In the verify code I have:
if (!(fFieldsChk[iLoop])&& (Ctrim == "") ) //check for empty field
{
alert (strField + " is null. " + "\n" + "Please complete the " + strField + " field.");
//------------------------ ---------- ---------- ---------- ---------- ---------- ---------- -------
// This is the area that checks for empty fields on the input form
// iLoop is an index to the elements of the form
//------------------------ ---------- ---------- ---------- ---------- ---------- ---------- -------
if (iLoop == 0)
{ return false; document.theForm.NewCourse ID.focus() ; }
if (iLoop == 1)
{ return false; document.theForm.CourseNam e.focus(); }
if (iLoop == 2)
{ return false; document.theForm.CourseDes c.focus(); }
.
.
.
break;
} // end of if (!(fFieldsChk[iLoop])&& (Ctrim == "") )
FORM:
<FORM METHOD="post" NAME="theForm" onsubmit="return verify(this)">
<table border="0" width="400" cellpadding="8" cellspacing="0" >
<tr >
<td ><b>Course ID: </b></td>
<td colSpan="2" rowSpan="1" ><INPUT maxlength="6" size="6" name="NewCourseID" colSpan="2"value=""></td>< /tr>
<tr>
<td ><b>CourseName:</b></td>
<% If ReEnterFlag = true Then %>
<td colspan="2"><INPUT name="CourseName" maxlength="35" value="<% Response.Write SaveInput(2) %>"></input></td></tr>
<% Else %>
<td colspan="2"><input name="CourseName" maxlength="35" value=" "></td></tr>
<% End If %>
</tr>
<tr>
<td ><b>Course Desc: </b></td>
<% If ReEnterFlag = true Then %>
<td colspan="2"><TEXTAREA name="CourseDesc" maxlength="1200" rows= "2" cols="65" wrap="wrap" ><% Response.Write SaveInput(3)%></TEXTAREA>< /td></tr>
<% Else %>
<td colspan="2"><TEXTAREA name="CourseDesc" maxlength="1200" rows= "2" cols="65" ></TEXTAREA></td></tr>
<% End If %>
</tr>
.
.
.
When I have an empty field onsubmit finds it, the cursor goes into the field for less than 2 seconds, and then proceeds with the execution. Does anyone see what is wrong? Thanks a lot
if (!(fFieldsChk[iLoop])&& (Ctrim == "") ) //check for empty field
{
alert (strField + " is null. " + "\n" + "Please complete the " + strField + " field.");
//------------------------
// This is the area that checks for empty fields on the input form
// iLoop is an index to the elements of the form
//------------------------
if (iLoop == 0)
{ return false; document.theForm.NewCourse
if (iLoop == 1)
{ return false; document.theForm.CourseNam
if (iLoop == 2)
{ return false; document.theForm.CourseDes
.
.
.
break;
} // end of if (!(fFieldsChk[iLoop])&& (Ctrim == "") )
FORM:
<FORM METHOD="post" NAME="theForm" onsubmit="return verify(this)">
<table border="0" width="400" cellpadding="8" cellspacing="0" >
<tr >
<td ><b>Course ID: </b></td>
<td colSpan="2" rowSpan="1" ><INPUT maxlength="6" size="6" name="NewCourseID" colSpan="2"value=""></td><
<tr>
<td ><b>CourseName:</b></td>
<% If ReEnterFlag = true Then %>
<td colspan="2"><INPUT name="CourseName" maxlength="35" value="<% Response.Write SaveInput(2) %>"></input></td></tr>
<% Else %>
<td colspan="2"><input name="CourseName" maxlength="35" value=" "></td></tr>
<% End If %>
</tr>
<tr>
<td ><b>Course Desc: </b></td>
<% If ReEnterFlag = true Then %>
<td colspan="2"><TEXTAREA name="CourseDesc" maxlength="1200" rows= "2" cols="65" wrap="wrap" ><% Response.Write SaveInput(3)%></TEXTAREA><
<% Else %>
<td colspan="2"><TEXTAREA name="CourseDesc" maxlength="1200" rows= "2" cols="65" ></TEXTAREA></td></tr>
<% End If %>
</tr>
.
.
.
When I have an empty field onsubmit finds it, the cursor goes into the field for less than 2 seconds, and then proceeds with the execution. Does anyone see what is wrong? Thanks a lot
all the if blocks should be like
{document.theForm.NewCours eID.focus( ); return false; }
other than that i dont see any problems
{document.theForm.NewCours
other than that i dont see any problems
<fyi>When javascript encounters a "return" command, it returns, period. Nothing further in that function will be executed</fyi>
ASKER
I changed the returns to the correct place and reran this. I still did not get the focus. Any suggestions?? Thanks
Program1.txt
Program1.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I went to FireFox and tried my page, and it worked!!!! I have to look into the problem in IE...
you can turn on "Display a notification about every script error" in IE
Go to Internet Options --> Browsing --> "Display a notification about every script error"
check that box and restart IE and try your form. You will most get an error there then =P
Go to Internet Options --> Browsing --> "Display a notification about every script error"
check that box and restart IE and try your form. You will most get an error there then =P
WRONG=> { return false; document.theForm.CourseDes
Secondly, your issue must lie in the code you are not displaying. You posted a fragment of your code. On that fragment it clearly shows under what conditions false is being returned. What it does not show is when/where are you returning true. Your form will not submit if you return false. Hence, the problem is elsewhere.