Hello,
I am trying to do a simple validation of a text form element that should only have numeric values. Below is the code I use to call a validation function from each form element, as well as for the functions themselves.
The problem lies with the focus() and select() functions in javascript. The functions correctly determine when an entered value is numeric or not, but do not subsequently select and focus on the correct, calling form element. Instead, the functions focus on the form element following the calling element. Any help greatly appreciated!
<input type=”text” name=”partic” size=”15″ onChange=”checkIt(this)”>
//***************************************************************************************************
//called by checkIt function; checks to see if passed string is a number or not
function isNumber(inputStr) {
for (var i = 0; i < inputStr.length; i++) {
var oneChar = inputStr.substring(i, i + 1)
if (oneChar < “0” || oneChar > “9”) {
alert(“You must enter a numeric value in this field.”)
return false
}
}
return true
}
//***************************************************************************************************
//***
//
//validates a text form element; calls isNumber function to see if passed value is a number
function checkIt(passed) {
inputStr = passed.value
if (isNumber(inputStr)) {
} else {
passed.focus();
passed.select();
}
}