D
DonO
Not sure why this isn't working. I'm building a function to check the
value of a form field to make sure it's numeric or a comma or period.
I know this could probably be done with a regex function, but that's
not my strong suit...
The part I don't understand is when it throws the error that the field
doesn't match the criteria, it fails to put the focus on the field. It
highlights it, but focus goes to the next text box.
Thanks,
D.
<script type="text/javascript">
function check_numeric(inObj){
var allowedChars = "1234567890,.";
var checkStr = inObj;
var curChar = '';
var chkChar = '';
var isNumber = 1;
for(i=0; i<checkStr.value.length; i++){
curChar = checkStr.value.charAt(i);
for (j = 0; j < allowedChars.length; j++){
if (allowedChars.charAt(j) == curChar) break;
if (j == (allowedChars.length-1)) isNumber = 0;
}
if(isNumber == 0){
alert('Only the following characters are allowed:\n
\n'+allowedChars);
document.getElementById
(inObj.id).style.background="#f99";
inObj.focus(); // not working
break;
}
}
if(isNumber == 1){
document.getElementById(inObj.id).style.background="#fff";
}
}
</script>
value of a form field to make sure it's numeric or a comma or period.
I know this could probably be done with a regex function, but that's
not my strong suit...
The part I don't understand is when it throws the error that the field
doesn't match the criteria, it fails to put the focus on the field. It
highlights it, but focus goes to the next text box.
Thanks,
D.
<script type="text/javascript">
function check_numeric(inObj){
var allowedChars = "1234567890,.";
var checkStr = inObj;
var curChar = '';
var chkChar = '';
var isNumber = 1;
for(i=0; i<checkStr.value.length; i++){
curChar = checkStr.value.charAt(i);
for (j = 0; j < allowedChars.length; j++){
if (allowedChars.charAt(j) == curChar) break;
if (j == (allowedChars.length-1)) isNumber = 0;
}
if(isNumber == 0){
alert('Only the following characters are allowed:\n
\n'+allowedChars);
document.getElementById
(inObj.id).style.background="#f99";
inObj.focus(); // not working
break;
}
}
if(isNumber == 1){
document.getElementById(inObj.id).style.background="#fff";
}
}
</script>