greatfalls
Technical User
I have a javascript that is doing a calculation and displaying some dollar values and I would like to display them on the output page as well, but the name of each field is the same. Which is name="salHistory" Is this possible?
function chkCurrency(fld) {
// insure currency input (no numeric sign allowed)
var str = fld.value.replace(/\$|\,|\s/g,'');
if (!/^[0-9]+\.?[0-9]{0,2}$/.test(str)) {
window.alert("This must be a valid currency value."
;
fld.focus();
fld.select();
return false;
}
fld.value = fmtCurrency(str);
// check field priorities
if (fld.name=="aveSalary"
{
for (var i=0; i<fld.form.salHistory.length; i++) {
fld.form.salHistory.value = "";
}
} else {
var cnt = 0, sum = 0;
for (var i=0; i<fld.form.salHistory.length; i++) {
if (fld.form.salHistory.value.length == 0) break;
cnt++;
sum += Number(fld.form.salHistory.value.replace(/\$|\,|\s/g,''));
}
for (i; i<fld.form.salHistory.length; i++) {
if (fld.form.salHistory.value.length > 0) break;
}
if (i<fld.form.salHistory.length) {
window.alert("Cannot skip a salary history year."
;
fld.form.salHistory[cnt].focus();
fld.form.salHistory[cnt].select();
return false;
}
str = (sum/cnt).toString();
fld.form.aveSalary.value = fmtCurrency(str);
}
return true;
}
<input type="text" name="salHistory" tabindex="20" size="6" onChange="return chkCurrency(this);">
<input type="text" name="salHistory" tabindex="21" size="6" onChange="return chkCurrency(this);">
function chkCurrency(fld) {
// insure currency input (no numeric sign allowed)
var str = fld.value.replace(/\$|\,|\s/g,'');
if (!/^[0-9]+\.?[0-9]{0,2}$/.test(str)) {
window.alert("This must be a valid currency value."
fld.focus();
fld.select();
return false;
}
fld.value = fmtCurrency(str);
// check field priorities
if (fld.name=="aveSalary"
for (var i=0; i<fld.form.salHistory.length; i++) {
fld.form.salHistory.value = "";
}
} else {
var cnt = 0, sum = 0;
for (var i=0; i<fld.form.salHistory.length; i++) {
if (fld.form.salHistory.value.length == 0) break;
cnt++;
sum += Number(fld.form.salHistory.value.replace(/\$|\,|\s/g,''));
}
for (i; i<fld.form.salHistory.length; i++) {
if (fld.form.salHistory.value.length > 0) break;
}
if (i<fld.form.salHistory.length) {
window.alert("Cannot skip a salary history year."
fld.form.salHistory[cnt].focus();
fld.form.salHistory[cnt].select();
return false;
}
str = (sum/cnt).toString();
fld.form.aveSalary.value = fmtCurrency(str);
}
return true;
}
<input type="text" name="salHistory" tabindex="20" size="6" onChange="return chkCurrency(this);">
<input type="text" name="salHistory" tabindex="21" size="6" onChange="return chkCurrency(this);">