JavaScript驗證功能我想驗證在codeignigter克林特側的形式。我有一個視圖和一個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();
聽起來愚蠢的問題,但是,你要驗證它提交? –
我看你已經在form_submit上使用validate()函數,但是,不必像'onSubmit =「validate()」'那樣使用它? –
是的,我想驗證上提交 – user2249227