81
rated 0 times
[
87]
[
6]
/ answers: 1 / hits: 21138
/ 12 Years ago, tue, july 17, 2012, 12:00:00
I'm been trying to validate my fields by using 'getElementById()' with '.value'. However, it seems like either getElementById.value is not working or some codes has overlap the function.
Updated Javascript function:
function validate() {
var Name = document.getElementById('Name').value;
var Tel = document.getElementById('Tel').value;
var FaxNo = document.getElementById('FaxNo').value;
if (Name != ) //wanted to check for alphabets only.
{
alert(Correct);
return true; //doesnt go to next.php
}
else
{
alert(Don leave blank!)
return false;
}
if (isNaN(Tel)) //check only numbers. Same code for FaxNo.
{
alert(Correct);
return true; //doesnt go to next.php
}
else
{
alert(invalid);
return false
}
return true; //doesn't go to next.php
}
My Form:
<Form action =next.php method=post>
<input name=Name type=text id=Name value=/>
<input name=Tel type=text id=Tel value=/>
<input name=FaxNo type=text id=FaxNo value=/>
<input type=submit name=submit onclick=return validate();/>
</Form>
I have already defined my onclick function to my Javascript and tried to add return false too. But the alert still cant appear. Kindly advise.
More From » html