2014-02-06 45 views
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> 
+0

你可以顯示你的HTML代碼嗎?因爲我無法理解你的控件(對象)的名字! – user2727841

+0

所以你沒有得到答案......我告訴你顯示你的HTML代碼! – user2727841

回答

0

重寫代碼,希望這會起作用!

如果(document.form4.type.value == 「現金 」){

如果(document.form4.Expanse_cash.value ==「」){

alert("Please Enter value"); 
return false; 

}

}

否則,如果(document.form4.type .value ==「check」){

if if(document.form4.cno。 == 「」){

alert ("Please Enter Cheque No "); 
return false;} 

}

其他{

警報( 「請選擇付款方式!」);

}