[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Focus on empty or error field will not "stick".

Posted on 2008-02-07
7
Medium Priority
?
232 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Kathrynmj
7 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 20845086
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
 
LVL 17

Expert Comment

by:contactkarthi
ID: 20845114
all the if blocks should be like  

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

other than that i dont see any problems
0
 
LVL 29

Expert Comment

by:Badotz
ID: 20845145
<fyi>When javascript encounters a "return" command, it returns, period. Nothing further in that function will be executed</fyi>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:Kathrynmj
ID: 20845480
I changed the returns to the correct place and reran this.  I still did not get the focus.  Any suggestions?? Thanks
Program1.txt
0
 
LVL 9

Accepted Solution

by:
Lakio earned 1000 total points
ID: 20852327
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
 

Author Closing Comment

by:Kathrynmj
ID: 31428997
I went to FireFox and tried my page, and it worked!!!!  I have to look into the problem in IE...
0
 
LVL 9

Expert Comment

by:Lakio
ID: 20853345
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Implementing simple internal controls in the Microsoft Access application.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question