SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Dynamic HTML :

Previous DiscussionNext Discussion
 JS that should work, but doesn't

The form handler validates the field for required data. When the user attempts to leave the field empty, they are prompted in an alert box and the function then focuses the cursor in that box, while changing the background color to highlight the users error. Everything works properly, except the cursor is focused on the next field rather than the error field. There is no logical explanation why it is skipping to the next field . Please help me figure out why and correct this error.

code is

function isNotEmpty(elem) {
var str = elem.value;
var nm = elem.name;
if(str == null || str.length == 0) {
alert("Please fill in the "+ nm +" field.");
document.getElementById(nm).style.backgroundColor = bgBad;
document.getElementById(nm).focus();
return false;
} else {
document.getElementById(nm).style.backgroundColor = bgGood;
return true;
}
}

Started By Techmaniac on Jun 20, 2007 at 9:46:27 AM

8 Response(s) | Reply

Earlier Replies | Replies 3 to 8 of 8 | Later Replies
Goto Page: 2 1
simonleung on Jun 21, 2007 at 6:41:12 AM (# 3)

document.getElementById(nm) should not return what you want


Techmaniac on Jun 21, 2007 at 11:38:27 AM (# 4)

It does return the proper name to the alert box, and colors the proper element. It just focuses on the element (textfield) after the appropriate element.

That's what makes this so frustrating, it works for two of the three methods, but doesn't complete the function as written.


sophia_star on Jul 2, 2007 at 6:56:59 AM (# 5)
This message has been edited.

Even i am facing this error , whats the solution ???



http://thepinholeglasses.eslblogs.org/


Badotz on Jul 10, 2007 at 4:33:39 PM (# 6)

If you want to do this:

document.getElementById(nm).focus();

you will have to change this:

var nm = elem.name;

to this:

var nm = elem.id;


Badotz on Jul 10, 2007 at 4:34:09 PM (# 7)

oh, and the element will need an value in the ID attribute, as well...


Jaky123 on Sep 26, 2007 at 4:10:17 PM (# 8)

Yeah,i agree that the element will need an value in the ID attribute.I think this is the problem.

 

iphone accessories

ipod video converter


Earlier Replies | Replies 3 to 8 of 8 | Later Replies
Goto Page: 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2004 InsideDHTML.com, LLC. All rights reserved.