![](/img/trans.png)
[英]Radio button validation not disappear when select a button using Formik and Yup
[英]facing in validation the is when i select radio button
主要問題是當我選擇現金單選按鈕時,第一個字段必須為必填項;如果我選擇第二個按鈕,則檢查字段必須為必填項...
當我提交數據驗證不起作用時,為此程序添加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>
重寫代碼,希望它能工作!
if(document.form4.type.value ==“ Cash ”){
如果 (document.form4.Expanse_cash.value ==“”){
alert("Please Enter value");
return false;
}
}
否則,如果 (document.form4.type.value ==“ cheque”){
如果 (document.form4.cno。 值 == “”){
alert ("Please Enter Cheque No ");
return false;}
}
其他{
alert(“請選擇一種付款方式!”);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.