473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

set focus() on error forms, please help

Hello,

I created a form to validate form fields for empty fields and check ssn. When I added the set focus() on, it does not work.
Can you help please to see why my does not work? it worked without the set focus() on.
thanks.

var err = 0
function ckform(){
if (document.form.Name.value=="") {
msgbox = msgbox + "\n Please enter your Name.";
if err == 0 {
document.form.Name.focus();
err = err + 1;
}
}
function chfr() {
var SSNvalue = document.form.SSN.value;
if(isNaN(SSNvalue) || SSNvalue.length != 9) { // not a number or length not equal to 9
msgbox = msgbox + "\n Please enter a valid ssn in corect format.";
if err == 0 {
document.form.SSN.focus();
err = err + 1;
}
}
}
Mar 26 '07 #1
1 1863
acoder
16,027 Expert Mod 8TB
You shouldn't use "Name" because it is an attribute name for many elements.

It might not make a difference, but you should have brackets () around your if conditional checking:
Expand|Select|Wrap|Line Numbers
  1. if (err == 0) {
Set the err value before giving focus to the element.

If you still have problems, post the form code.
Mar 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
10
by: tshad | last post by:
I have a page where I give focus to the first textbox on my page: <body onLoad="document.forms.firstName.focus();"> I also go and check the status of some data when I exit the 3rd textbox on...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.