Alv
05-07-2003, 02:26 AM
I have a numerical checking function.
function IsNumeric(field) {
var valid = "0123456789"
var ok = "true";
var temp;
for (var i = 0; i < field.value.length; i++) {
temp = "" + field.value.substring(i, i + 1);
if (valid.indexOf(temp) == "-1")
ok = "false";
}
if (ok == "false") {
alert("Invalid input. Please enter only numbers.");
field.focus();
field.select();
}
}
I have this HTML input textbox.
<INPUT TYPE="text" NAME="Quantity" MAXLENGTH="3" SIZE="3" VALUE="0" CLASS="text" onChange="IsNumeric(this); document.Form.Manpower.value = document.Form.Quantity.value * document.Form.Day.value; document.Form.Amount.value = document.Form.Manpower.value * document.Form.Rate.value">
My question, how do I prevent the subsequent javascript from executing if the user input non numeric data? I do not want this portion to be executed "document.Form.Manpower.value = document.Form.Quantity.value * document.Form.Day.value; document.Form.Amount.value = document.Form.Manpower.value * document.Form.Rate.value".
Thanks in advance.
function IsNumeric(field) {
var valid = "0123456789"
var ok = "true";
var temp;
for (var i = 0; i < field.value.length; i++) {
temp = "" + field.value.substring(i, i + 1);
if (valid.indexOf(temp) == "-1")
ok = "false";
}
if (ok == "false") {
alert("Invalid input. Please enter only numbers.");
field.focus();
field.select();
}
}
I have this HTML input textbox.
<INPUT TYPE="text" NAME="Quantity" MAXLENGTH="3" SIZE="3" VALUE="0" CLASS="text" onChange="IsNumeric(this); document.Form.Manpower.value = document.Form.Quantity.value * document.Form.Day.value; document.Form.Amount.value = document.Form.Manpower.value * document.Form.Rate.value">
My question, how do I prevent the subsequent javascript from executing if the user input non numeric data? I do not want this portion to be executed "document.Form.Manpower.value = document.Form.Quantity.value * document.Form.Day.value; document.Form.Amount.value = document.Form.Manpower.value * document.Form.Rate.value".
Thanks in advance.