Hello,
I am very new to Javascript and I've only understanding for simple Javascript.
I had to develop a Javascript validation form for a project. I have done so, using the most simple methods. After submitting the form, the appropriate errors show, but, when resubmitted, the errors are not updated (they are still present). I've had a few ideas about fixing this, but I'm so new to Javascript that my knowledge of commands are restricted heavily. I have seen other functioning forms but most are a lot more complex than mine. Is there a simple rule I can incorporate to fix my Javascript form? I'm guessing I'll need another function.
Now, the web page (and even the form) is quite large, so I'll just show the script:
I am very new to Javascript and I've only understanding for simple Javascript.
I had to develop a Javascript validation form for a project. I have done so, using the most simple methods. After submitting the form, the appropriate errors show, but, when resubmitted, the errors are not updated (they are still present). I've had a few ideas about fixing this, but I'm so new to Javascript that my knowledge of commands are restricted heavily. I have seen other functioning forms but most are a lot more complex than mine. Is there a simple rule I can incorporate to fix my Javascript form? I'm guessing I'll need another function.
Now, the web page (and even the form) is quite large, so I'll just show the script:
Code:
<script type="text/javascript" language="javascript">
// This form is only a 'template'. The server has not been manipulated to process the results yet.
function Validateform(f1)
{
if (document.f1.firstname.value=="")
{
document.getElementById("e1").innerHTML="* Error: Please Enter your first name ";
}
if (document.f1.lastname.value=="")
{
document.getElementById("e2").innerHTML="* Error: Please Enter your last name ";
}
if (document.f1.a1.value.length<4)
{
document.getElementById("e3").innerHTML="* Error: Please Enter your address (it must be longer than 4 characters) ";
}
if (document.f1.city.value=="")
{
document.getElementById("e4").innerHTML="* Error: Please Enter your City ";
}
if (document.f1.postcode.value.length!=4)
{
document.getElementById("e5").innerHTML="* Error: Please Enter your postcode (4 digits) ";
}
if (document.f1.phone.value=="")
{
document.getElementById("e6").innerHTML="* Error: Please Enter your phone number ";
}
if ((document.f1.d1[0].checked==false) && (document.f1.d1[1].checked==false) && (document.f1.d1[2].checked==false))
{document.getElementById("e7").innerHTML="* Error: Please Enter your chosen payment cost ";}
if ((document.f1.p1[0].checked==false) && (document.f1.p1[1].checked==false) && (document.f1.p1[2].checked==false) && (document.f1.p1[3].checked==false))
{document.getElementById("e8").innerHTML="* Error: Please Enter your chosen payment method ";}
if ((document.f1.lastname.value=="") || (document.f1.firstname.value=="") || (document.f1.a1.value.length<4) || (document.f1.city.value=="") || (document.f1.postcode.value.length!=4) || ((document.f1.d1[0].checked==false) && (document.f1.d1[1].checked==false) && (document.f1.d1[2].checked==false)) || ((document.f1.p1[0].checked==false) && (document.f1.p1[1].checked==false) && (document.f1.p1[2].checked==false) && (document.f1.p1[3].checked==false)))
{
return false;
}
return true;
// This is a very simple validation function and it does have an annoying fault. The Errors do not update once solved.
}
</script>
Comment