我想在 codeignigter 的 clint 端验证一个表单。我有一个视图和一个 javascript 函数。我如何调用 javascript 函数来验证表单。这是我的代码
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();