D
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_customer_unit_price(fieldname,fieldlabel,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=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
}
}
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,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=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
}
}