主要问题是当我选择现金单选按钮时,第一个字段必须是强制性的,如果我选择第二个按钮,那么检查字段必须是修饰的...
当我提交数据验证不起作用时,为该程序添加HTML代码
<form action="add_file.php" method="post" enctype="multipart/form-data" name="form4">
<table width="400" align="center" cellspacing="10" >
<tr>
<td></td>
</tr>
<tr>
<td style="width:200px;"><label class="label">Purchase Date:</label></td>
<td><input type="text" name="Purchase_date" id="datepicker" class="button" /></td>
</tr>
<tr>
<td style="width:200px;"><label class="label">Expanse Head:</label></td>
<td><input type="text" name="Expanse_head" class="button" /></td>
</tr>
<tr>
<td style="width::200px"><label class="label">Type of Payment:</label></td>
<td><input type="radio" name="type" value="cash" />
cash
<input type="radio" name="type" value="cheque"/><label>
cheque</label></td>
</tr>
<tr>
<td style="width:200px;"><label class="label">Expanse Cash:</label></td>
<td><input type="text" name="Expanse_cash" class="button" pattern="[0-9]+" required title="Please Enter Digits"/></td>
</tr>
<tr>
<td style="width:200px;"><label class="label">Cheque No</label></td>
<td><input type="text" name="cno" class="button" /></td>
</tr>
<tr style="margin-top:100px;">
<td><label class="label">Bill</label></td>
<td><input type="file" name="uploaded_file" /></td>
</tr>
<tr style="margin-top:100px;">
<td></td>
<td><input type="submit" value="Save" onclick="return validate(this);" /></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
<script>
function validate(){
if(document.form4.Purchase_date.value==""){alert("Please Enter Date"); return false;}
if(document.form4.Expanse_head.value==""){alert("Please Enter Expanse Head"); return false;}
/*if(document.form4.type.value=="1"){
(document.form4.Expanse_cash.value=="")
{alert("Please Enter value"); return false;}}
else(document.form4.type.value=="cheque")
{
(document.form4.cno=="");
{alert ("Please Enter Cheque No "); return false;}}*/
if(document.form4.uploaded_file.value==""){alert("Please upload file"); return false;}
}
</script>
答案 0 :(得分:0)
重写代码,希望这会有效!!
如果(document.form4.type.value == “的现金强>”){
如果强>(document.form4.Expanse_cash.value == “”){
alert("Please Enter value");
return false;
}
}
else if else (document.form4.type.value ==“check”){
如果强>(document.form4.cno。的值强> == “”){
alert ("Please Enter Cheque No ");
return false;}
}
否则{
提醒(“请选择付款方式!!”);
}