S
simina
Hi...
I have a form with 4 number fields: phone area, phone number, cell
area, cell number.
I did a function that checks the "number" issue for all 4 fields in
the same time (because the code is onBlur: "return ph(this);"). Now
the problem is that if the user hits Enter data still goes to the
database (of course, because I should have the function called in the
form's onSubmit......
But how can I do this because I should now have 4 personalized
functions for each field (maybe) or 1 function that comprise the code
for all 4 fields??!!
I am just lost...I started JavaScript 3 weeks ago and I'm in a
profound agony...
The code looks like this (and maybe even this one has a problem):
function ph(obj){
var checkVal="0123456789";
var objVal=obj.value;
var ok=true;
for(i=0;i<objVal.length;i++)
{
var myChar=objVal.charAt(i);
for(j=0;j<checkVal.length;j++)
if (myChar==checkVal.charAt(j)) break;
if(j==checkVal.length)
{
ok=false;
break;
}
}
if(!ok) //myChar is not in [0,9]
{
alert("This is not a valid value. Please enter a number!");
obj.focus();
return false;
}
return true;
}
Thanks...
I have a form with 4 number fields: phone area, phone number, cell
area, cell number.
I did a function that checks the "number" issue for all 4 fields in
the same time (because the code is onBlur: "return ph(this);"). Now
the problem is that if the user hits Enter data still goes to the
database (of course, because I should have the function called in the
form's onSubmit......
But how can I do this because I should now have 4 personalized
functions for each field (maybe) or 1 function that comprise the code
for all 4 fields??!!
I am just lost...I started JavaScript 3 weeks ago and I'm in a
profound agony...
The code looks like this (and maybe even this one has a problem):
function ph(obj){
var checkVal="0123456789";
var objVal=obj.value;
var ok=true;
for(i=0;i<objVal.length;i++)
{
var myChar=objVal.charAt(i);
for(j=0;j<checkVal.length;j++)
if (myChar==checkVal.charAt(j)) break;
if(j==checkVal.length)
{
ok=false;
break;
}
}
if(!ok) //myChar is not in [0,9]
{
alert("This is not a valid value. Please enter a number!");
obj.focus();
return false;
}
return true;
}
Thanks...