i want to validate a form in clint side in codeignigter. i have a view and a javascript function. how can i call the javascript function to validate the form. here is my code
function validate()
{
var txtSchoolName=document.getElementById('name');
var address=document.getElementById('address');
var contactNo1=document.getElementById('contactNo1');
if((name.value==null)||(name.value=="")){
alert("Enter School Name")
name.focus()
return false
}
if((address.value==null)||(address.value=="")){
alert("Provide Address")
address.focus()
return false
}
if((contactNo1.value==null)||(contactNo1.value=="")){
alert("Provide Contact Number")
contactNo1.focus()
return false
}
return true
}
</script>
echo form_open_multipart('register_school/updateSchool');
echo '<p>';
echo '</br>';
echo form_label('School Name : ','username',$attributes);
echo form_input('name');
echo form_label('School Address : ','username',$attributes);
echo form_input('address');
echo form_label('Contact No 1 : ','username',$attributes);
echo form_input('contactNo');
echo form_submit('submit', 'Save','validate()');
echo form_close();