473,775 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with focus() after validation

Dan


This function validates a price field on my form. It fires with onchange.
If the validation fails, I want the focus to return to the same field so
that the user can correct it. The way it is working now, the focus moves
to whichever field is clicked upon exiting this field. The behavior is the
same in ie,ns and opera. This is probably simple, but I don't understand
why this doesn't work Any ideas would be much appreciated. Thanks.

Dan
function confirm_custome r_unit_price(fi eldname,fieldla bel,fieldindex)
{
// fieldname: the name of the element
// fieldlabel: text to be displayed in alert box
// fieldindex: row number of the element

// get the value in the field
var thevalue=docume nt.form1[fieldname].value
// do the actual validation in another function. this works fine
var valid=isSignedF loat(thevalue)

if (valid)
// if the value is ok, write to an array where I do some more processing
later
{customerprice[fieldindex]=thevalue
return true;}
else
{
// value is not ok. show the alert.
alert(fieldlabe l +' is not valid');
// write a zero to the array, because I cant use the value that was
submitted
customerprice[fieldindex]=0
// return the focust to the offending field
document.form1[fieldname].focus();
//I also tried this, but it doesn't work either
document.getEle mentById(fieldn ame).focus();
return true
}
}
Jul 20 '05 #1
3 5374
In article <z1wnb.49347$Fm 2.25196@attbi_s 04>,
ji****@aol.nosp am.please.com enlightened us with...
// return the focust to the offending field
document.form1[fieldname].focus();


document.form1. fieldname.focus ();

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #2
Dan
This function validates a price field on my form. It fires with onchange.
If the validation fails, I want the focus to return to the same field so
that the user can correct it. The way it is working now, the focus moves
to whichever field is clicked upon exiting this field. The behavior is the
same in ie,ns and opera. This is probably simple, but I don't understand
why this doesn't work Any ideas would be much appreciated. Thanks.

Dan
function confirm_custome r_unit_price(fi eldname,fieldla bel,fieldindex)
{
// fieldname: the name of the element
// fieldlabel: text to be displayed in alert box
// fieldindex: row number of the element

// get the value in the field
var thevalue=docume nt.form1[fieldname].value
// do the actual validation in another function. this works fine
var valid=isSignedF loat(thevalue)

if (valid)
// if the value is ok, write to an array where I do some more processing
later
{customerprice[fieldindex]=thevalue
return true;}
else
{
// value is not ok. show the alert.
alert(fieldlabe l +' is not valid');
// write a zero to the array, because I cant use the value that was
submitted
customerprice[fieldindex]=0
// return the focust to the offending field
document.form1[fieldname].focus();
//I also tried this, but it doesn't work either
document.getEle mentById(fieldn ame).focus();
return true
}
}

"kaeli" <in************ ********@NOSPAM att.net> wrote in message
news:MP******** *************** *@nntp.lucent.c om...
In article <z1wnb.49347$Fm 2.25196@attbi_s 04>,
ji****@aol.nosp am.please.com enlightened us with...
// return the focust to the offending field
document.form1[fieldname].focus();


document.form1. fieldname.focus ();

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------

in this function, fieldname is a variable. many different text fields use
this for validation. without the [] notation the script thinks I have a
field named 'fieldname' and I get the an error something like "fieldname is
null or not an object.
Jul 20 '05 #3
And on the day Tue, 28 Oct 2003 17:00:30 GMT,
ji****@aol.nosp am.please.com enlightened us with <Ogxnb.50056$Tr 4.106035
@attbi_s03>...
This function validates a price field on my form. It fires with onchange.
If the validation fails, I want the focus to return to the same field so
that the user can correct it. The way it is working now, the focus moves
to whichever field is clicked upon exiting this field. The behavior is the
same in ie,ns and opera. This is probably simple, but I don't understand
why this doesn't work Any ideas would be much appreciated. Thanks.


Yeah, and I showed you your error.

Change
document.form1[fieldname].focus();


to
document.form1. fieldname.focus ();

--------------------------------------------------
~kaeli~
Kill one man and you are a murderer. Kill millions
and you are a conqueror. Kill everyone and you
are God.
http://www.ipwebdesign.net/wildAtHeart/
http://www.ipwebdesign.net/kaelisSpace/
------------------------------------------------
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1523
by: Czarina | last post by:
hi guys! here I am again, bugging you Here is where my page stands right now: http://www.gainesvillewebs.com/czar...h_results-2.htm The top 2 forms are working just fine, but the bottom one, with the check boxes, it not working I am by NO MEANS, a Javascript expert, so please be patient! Here is what it needs to do: It need to check that at least 1 checkbox is selected, and if not, display error message.
4
2219
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 time and there is also a check on that. If time is empty return error message. Again the explorer returns error message and then shifts the focus to date field, again error message and focus goes to time and this story goes on and on, untill...
7
1414
by: Ray | last post by:
Hi all, I'm new to JavaScript and am trying to create a client side JavaScript form validation script. I'm doing ok with validating text input boxes but have a problem that I have not been able to solve and one I hope someone will help me resolve. I want to check the contents of a drop down box and if a certain item is selected, check the contents of a text input box to see if a any text was entered. If no text is entered, I want to...
5
11381
by: tshad | last post by:
I have a date validation function that I want to stay at the object I am validating if there is a Validation error, but it always goes to the next object. The Javascript: function ValidateForm(me){ var dt=me if (isDate(dt.value)==false){ dt.focus()
2
1646
by: Vinny | last post by:
A customer wants me to convert a VB app I wrote for them into a web app for remote users to do data entry. So, I'm writing a small ASP program which prompts the user for data, much like a VB program. I would like to interactively validate the data as they are entering it, rather than waiting until they submit the form. So, I am doing something like this (this is a very simple example): <head>
14
2155
by: JNariss | last post by:
Hello, I am fairly new to asp and jscript and am now in the process of learning some form validation. I am taking one step at a time by validating each field and testing it before moving onto the next one to be sure I am correct. I ran into a problem with my validation when I added an else if code to my code. Here is what I tried to do: Form (ITTermination) has a field (EmployeeName) which I would like to validate to check for no...
16
2818
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
1
1452
by: runway27 | last post by:
i have a registration page where a user fills up a form such as username, first name, phone number etc. i need to do a validation for the following fields. any help will be greatly appreciated. 1. for a text field if for example a user hits the space bar and then types the information with the validation i have the code ignores those initial spaces but actually these are spaces i need to insert these values in a database so these spaces...
1
1620
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first dropdown but nothing there after. I always get the error saying is null or not an object. I need help trying to figure out how to access the ojects in this form. Now in my body I have a <form> and it's name is form1 and I also have another <form>...
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9916
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.