Wednesday, 18 November 2009

Website Part III: The Taming of the Javascript

So today was a very very happy day. I continued with javascript and after a lot of persistance it all worked. Here it is below.

function validate_form(){
if (document.contactform.name.value == "" ){
alert ( "Please enter your Name." );
return validate_name = false;
}else{
validate_name = true;
}
if (document.contactform.email.value == ""){
alert ( "Please enter your Email Address.");
return validate_email=false;
}else{
validate_email=true;
}
if ((document.contactform.email.value.indexOf(".") > 2) && (document.contactform.email.value.indexOf("@") > 0)){
validate_validemail=true;
}else{
alert ( "Please enter a valid Email Address." );
return validate_validemail=false;
}
if (document.contactform.message.value == "" ){
alert ( "Please enter your Message." );
return validate_message = false;
}else{
validate_message = true;
}
}


This is only my validation javascript. All of these but 1 controls whether the box is empty or not and if it is a small alert box appears telling them to fill it in. The only different bit of code is the email validation one which can tell whether the email address is valid or not. It checks to see if there is an @ sign within the email and if there is a . (because there should be like.co.uk or .com). This will then hopefully make sure the email address I recieve is at least valid and possibly real (I do understand that fake email addresses can be typed in but to code that is currently out of my skill set).

Well thats all I achieved today but hopefully you understand that this is a very very big thing and it took me 6+ hours to get to work. But it now does and I am every so happy. Time for bed cheerio!

No comments:

Post a Comment