SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validations reqd

    In my script below I have a field called Mode Of Deposition.It has 4 radio buttons cash,cheque,dd,Online transfer.
    On cheque,dd,online transfer there are automatically generated text boxes on click.
    I want validations such dat wen cheque is clicked the text box generated Cheque No. shld be made compulsory.Similarly DD no if dd is clicked and Trasnsacion Id if online transfer is clicked.

  2. #2
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
     
    
     
     
    <script type="text/javascript"> 
    function show(val)
     {
     
      if(val=="1")
      {
      document.getElementById('row_online').style.display = "none";
      document.getElementById('row_dd').style.display = "none";
      document.getElementById('row_chq').style.display = "none";  
      }
      
     if(val=="2")
      {
      document.getElementById('row_online').style.display = "none";
      document.getElementById('row_dd').style.display = "none";
      document.getElementById('row_chq').style.display = "table-row";  
      }
      if(val=="3")
      {
      document.getElementById('row_online').style.display = "none";
      document.getElementById('row_chq').style.display = "none";
      document.getElementById('row_dd').style.display = "table-row";
      }
      
       if(val=="4")
      {
      document.getElementById('row_dd').style.display = "none"; 
      document.getElementById('row_chq').style.display = "none";  
      document.getElementById('row_online').style.display = "table-row";  
      }
     }
     </script>
     
    </head>
    <body>
    <table id="page">
    <tr><td >
    <br>
    
    
    <form name="form1" method="post">
    
    
    <TABLE class="tbl"  width="100%" ALIGN="CENTER" CELLPADDING="0" CELLSPACING="1" BGCOLOR="#E4EEE3">
                                      <TR><TD colspan="2" align="center">&nbsp; <strong>Bank Deposit Form</strong></TD> </TR>            
                                                                 
                                      <TR>
                                        <TD BGCOLOR="#FFFFFF">Amount in Rs <span style="color:#FF0000"> * </span></TD>
                                        <TD BGCOLOR="#FFFFFF"><input type="TEXT" name="amnt" size="15" >                                   </TD>
                                </TR>
                  
                  
                  
                  <TR>
                    <TD BGCOLOR="#FFFFFF">Invoice No. </TD>
                    <TD BGCOLOR="#FFFFFF"><input type="text" name="inv_no"></TD>
          </TR>
                   
                  
                                 
                 <TR> 
                 <TD BGCOLOR="#FFFFFF"> Mode Of Deposition <span style="color:#FF0000"> * </span></TD>
                  <TD BGCOLOR="#FFFFFF">
                  <label><INPUT TYPE="RADIO" NAME="radio1" VALUE="1" onClick="show(this.value)"> Cash </label> &nbsp; &nbsp;
                  <label><INPUT TYPE="RADIO" NAME="radio1" VALUE="2" onClick="show(this.value)"> Cheque </label> &nbsp; &nbsp;
                  <label><INPUT TYPE="RADIO" NAME="radio1" VALUE="3" onClick="show(this.value)"> DD </label> &nbsp; &nbsp;
                  <label><INPUT TYPE="RADIO" NAME="radio1" VALUE="4" onClick="show(this.value)"> Online Transfer </label>&nbsp;&nbsp;              </TD>
                </TR>
                
                 <TR id="row_chq" style="display:none"> 
                 <TD BGCOLOR="#FFFFFF">&nbsp;</TD>
                 <TD BGCOLOR="#FFFFFF">Cheque No. &nbsp; <input type="text" name="chq_no"></TD>
                 </TR>
                  <TR id="row_dd" style="display:none"> 
                 <TD BGCOLOR="#FFFFFF">&nbsp;</TD>
                 <TD BGCOLOR="#FFFFFF">DD No. &nbsp; <input type="text" name="dd_no"></TD>
                 </TR>           
                  <TR id="row_online" style="display:none"> 
                 <TD BGCOLOR="#FFFFFF">&nbsp;</TD>
                 <TD BGCOLOR="#FFFFFF">Transaction Id &nbsp; <input type="text" name="transc_id"></TD>
                 </TR>           
                 <TD colspan="2" align="center"> <input name="submit" type="SUBMIT" value="Add" onClick="return validate();"></TD>
                 </TR>  
                             </TABLE>
          </FORM>
     <script language="JavaScript" type="text/javascript">
      function validate(){
      
     
      var radioButtons1 = document.getElementsByName("radio1");
      for (var y = 0; y < radioButtons1.length; y ++) {
      if (radioButtons1[y].checked)
      {var msgg="yes" ;   break}
      }
        
      if(msgg!="yes"){alert("Select atleast one mode to Deposit Amount");  return false}
      
      var radioButtons = document.getElementsByName("radio1");  
       for (var x = 0; x < radioButtons.length; x++) {
       
       
           if (radioButtons[x].checked)
          {
          if(radioButtons[x].value=="1")
          {
          }   
          if(radioButtons[x].value=="2")
          { 
                 frmvalidator.addValidation("chq_no","req","Please Enter CHEUQE NO.");
                 frmvalidator.addValidation("chq_no","numeric","Only digits are allowed in CHEUQE NO."); 
             
          }
          
           if(radioButtons[x].value=="3")
          {
          frmvalidator.addValidation("dd_no","req","Please Enter DD NO.");
          frmvalidator.addValidation("dd_no","numeric","Only digits are allowed in DD NO."); 
          
          }
          
          if(radioButtons[x].value=="4")
          { 
                 frmvalidator.addValidation("transc_id","req","Please Enter Transaction Id");
                 frmvalidator.addValidation("transc_id","numeric","Only digits are allowed in Transaction Id"); 
           
          }
          
            }
      
         }
       
      
       
    }
     
     </script>
     <br/>
     
      
                      
    </td> </tr>
    </table>
    
    <TABLE WIDTH="100%" CELLPADDING="1" CELLSPACING="1" BGCOLOR="<?php print "$HRColour"; ?>">
      <TR> 
        <TD></TD>
      </TR>
    </TABLE>
      
    </body>
    </html>
    I have tried above method of validations ,but its not working.Run it at your end,to get a better idea of my problem!
    Plz help!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •