I was pretty ill for the last couple of weeks so missed the lectures, but I've been working hard on my site and getting it operating. I thought I would share with you some of what I've been doing.
Javascript form validation
I've learnt how to validate forms by checking if a field is empty...
if (form.name.value == "") {
alert( "Please enter the name of the resources." );
form.name.focus();
return false ;
}
(For this you need to specify the name of the field you want to validate (name) and if necessary, the id of the form (in this case 'form'))
... and check two passwords are the same
if (form.password.value != form.retypePassword.value)
{
alert("The two passwords are not the same.");
form.retypePassword.focus();
return false;
}
(This specifies the two password fields- 'password' and 'retypePassword')
To make these validations happen, you need to put them inside a function (in this case 'checkform') and add to the form an 'onsubmit' that executes the fuction, ie.
onsubmit="return checkform(this)
No comments:
Post a Comment