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.NewCourseID.focus(); }
            if (iLoop  ==  1)
                  { return false; document.theForm.CourseName.focus(); }
            if (iLoop  ==  2)
                  { return false; document.theForm.CourseDesc.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
KathrynmjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
First of all, you need to focus first then return false:
WRONG=> { return false; document.theForm.CourseDesc.focus(); }
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.
0
contactkarthiCommented:
all the if blocks should be like  

{document.theForm.NewCourseID.focus();  return false; }

other than that i dont see any problems
0
BadotzCommented:
<fyi>When javascript encounters a "return" command, it returns, period. Nothing further in that function will be executed</fyi>
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

KathrynmjAuthor Commented:
I changed the returns to the correct place and reran this.  I still did not get the focus.  Any suggestions?? Thanks
Program1.txt
0
LakioCommented:
Use firefox, go to the page and open Error console.
Then try submiting and my guess is that where will be an error in error console, tell us what erorr comes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KathrynmjAuthor Commented:
I went to FireFox and tried my page, and it worked!!!!  I have to look into the problem in IE...
0
LakioCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.