Connecting Tech Pros Worldwide Help | Site Map

Help with focus() after validation

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 11:24 AM
Dan
Guest
 
Posts: n/a
Default Help with focus() after validation



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_customer_unit_price(fieldname,fieldlabel,f ieldindex)
{
// 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=document.form1[fieldname].value
// do the actual validation in another function. this works fine
var valid=isSignedFloat(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(fieldlabel +' 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.getElementById(fieldname).focus();
return true
}
}



  #2  
Old July 20th, 2005, 11:24 AM
kaeli
Guest
 
Posts: n/a
Default Re: Help with focus() after validation

In article <z1wnb.49347$Fm2.25196@attbi_s04>,
jitdsm@aol.nospam.please.com enlightened us with...[color=blue]
> // return the focust to the offending field
> document.form1[fieldname].focus();[/color]

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
-------------------------------------------------
  #3  
Old July 20th, 2005, 11:25 AM
Dan
Guest
 
Posts: n/a
Default Re: Help with focus() after validation

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_customer_unit_price(fieldname,fieldlabel,f ieldindex)
{
// 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=document.form1[fieldname].value
// do the actual validation in another function. this works fine
var valid=isSignedFloat(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(fieldlabel +' 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.getElementById(fieldname).focus();
return true
}
}



"kaeli" <infinite.possibilities@NOSPAMatt.net> wrote in message
news:MPG.1a08517235949561989915@nntp.lucent.com...[color=blue]
> In article <z1wnb.49347$Fm2.25196@attbi_s04>,
> jitdsm@aol.nospam.please.com enlightened us with...[color=green]
> > // return the focust to the offending field
> > document.form1[fieldname].focus();[/color]
>
> 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
> -------------------------------------------------[/color]


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.


  #4  
Old July 20th, 2005, 11:25 AM
kaeli
Guest
 
Posts: n/a
Default Re: Help with focus() after validation

And on the day Tue, 28 Oct 2003 17:00:30 GMT,
jitdsm@aol.nospam.please.com enlightened us with <Ogxnb.50056$Tr4.106035
@attbi_s03>...[color=blue]
> 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.
>[/color]

Yeah, and I showed you your error.

Change[color=blue][color=green][color=darkred]
> > > document.form1[fieldname].focus();[/color]
> >[/color][/color]

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/
------------------------------------------------
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.