Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need double validation check

Status
Not open for further replies.

greatfalls

Technical User
Jul 1, 2001
21
0
0
CA
I have many pages of validation (to much to post)of the below piece of a form.
One is the below function, when I would put values that didn't pass the validation into the below script, the alert works but in Netscape, I would get this highlighted and freezing effect. I found that by taking out the window.alerts this didn't happen. (this didn't happen with other window.alert functions in the form) I don't know why this happens, if anyone could figure this out I would be very grateful. (so for now I have blocked out the window.alerts in this function) My second problem is to do a double validation, since after the focus and select it lets you continue, with bad data (non numbers) put into the fields.
I am dealing with a array and am not sure how to do an on submit validaton - with an array. - The fields can be blank, if not blank have to be numbers and of the 5 boxes (fields) - they all don't have to be filled in but can't skip from box 1 to box 3 - so how would I move the below onchange to also be a final validation when hit the submit button?

function validateForm(theForm) {

if (!calcCurrentService(theForm, 'final')) return false;
if ( isAverageSalary(theForm) &&
isPercentIncrease(theForm) &&
isValidAge(theForm) &&
isSalaryHistory (theForm) &&

isValidStartService(theForm) ) {
var aveSalary = theForm.aveSalary.value;
} else {
return false;
}

<input type=&quot;text&quot; name=&quot;aveSalary&quot; tabindex=&quot;27&quot; size=&quot;8&quot; onChange=&quot;return chkCurrency(this);&quot;>

function chkCurrency(fld)
{
var str = fld.value.replace(/\$|\,|\s/g,'');
if (!/^[0-9]+\.?[0-9]{0,2}$/.test(str)) {
//window.alert(&quot;This must be a valid currency value.&quot;);

fld.focus();
fld.select();
return false;
}
fld.value = fmtCurrency(str);
var fldAry = new Array();
fldAry[0] = fld.form.salHistoryCur;
fldAry[1] = fld.form.salHistoryLessOne;
fldAry[2] = fld.form.salHistoryLessTwo;
fldAry[3] = fld.form.salHistoryLessThree;
fldAry[4] = fld.form.salHistoryLessFour;



var cnt = 0, sum = 0;
for (var i=0; i<fldAry.length; i++) {
if (fldAry.value.length == 0) break;
cnt++;
sum += Number(fldAry.value.replace(/\$|\,|\s/g,''));
}
for (i; i<fldAry.length; i++) {
if (fldAry.value.length > 0) break;
}
if (i<fldAry.length) {
//window.alert(&quot;Cannot skip a salary history year.&quot;);

fldAry[cnt].focus();
fldAry[cnt].select();
return false;
}
str = (sum/cnt).toString();
fld.form.aveSalary.value = fmtCurrency(str);
}
return true;
}
function fmtCurrency(str) {
// convert numeric string to currency format
cents = Math.floor((str*100+0.5)%100);
str = Math.floor((str*100+0.5)/100).toString();
if (cents < 10) cents = &quot;0&quot; + cents;
// return currency format
return (str + '.' + cents);
}


<input type=&quot;image&quot; value=&quot;calculate&quot; src=&quot;graphics/calculate_e.gif&quot; width=&quot;90&quot; height=&quot;20&quot; border=&quot;0&quot; alt=&quot;Calculate&quot; name=&quot;Calculate&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top