0
主要問題是當我選擇單選按鈕的現金,然後第一場必須是強制性的,如果我選擇第二個按鈕,然後檢查場必須是mendatory ...
添加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>
你可以顯示你的HTML代碼嗎?因爲我無法理解你的控件(對象)的名字! – user2727841
所以你沒有得到答案......我告訴你顯示你的HTML代碼! – user2727841