SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio Groups--Validation! NEED HELP!

    Hi all,

    I am trying to validate my radio groups. I have a page which has about 30 questions. I have created a radio group for each questions. All questions are in a form. I just want to validate the radio buttons/groups to make sure all questions are answered when the submit button is pressed. I dont care which one is selected.

    Could you please help me? :'(
    Thanks a lot in advance.

  2. #2
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post what code you have at this point? We can help if we can see what you've done!

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Sample Html -

    Quote Originally Posted by dc dalton
    Can you post what code you have at this point? We can help if we can see what you've done!
    Here is what I have on this page;

    Code:
    <% if len(request.form("Submit"))<=0 then %> 
    <form name="form1" method="POST" action="samePage.asp">
    
    <table>
        
        <tr> 
          <td><b>Q1. </b> <strong>Do you have a high need to take this online course? </strong></td> 
          </tr> 
        <tr> 
          <td> <p> 
              <input type="radio" name="R1" value="Yes"> Yes
              <input type="radio" name="R1" value="No"> No
               <br> 
            </p></td> 
          </tr> 
        <tr> 
          <td ><b>Q2. </b> <strong>Are you comfortable working on computers? </strong></td> 
          </tr> 
        <tr> 
          <td bgcolor="#EAEAD5"><p> 
              <input type="radio" name="R2" value="Yes"> Yes
              <input type="radio" name="R2" value="Somewhat">   Somewhat
              <input type="radio" name="R2" value="No">  No 
             <br> 
            </p></td> 
          </tr> 
        <tr> 
          <td width="100%" bgcolor="#CCCC99"><b>Q3. Do you have good keyboarding skills? </b></td> 
          </tr> 
        <tr> 
          <td 
        <input type="radio" name="R3" value="Yes"> Yes
        <input type="radio" name="R3" value="Somewhat"> Somewhat
         <input type="radio" name="R3" value="No"> No
            </td> 
          </tr> 
        <tr> 
          <td ><b>Q4. Can you run the applications you need to use on a computer? Examples: PowerPoint, Excel, Flash </b></td> 
          </tr> 
        <tr> 
          <td bgcolor="#EAEAD5"> 
           <input type="radio" name="R4" value="Yes"> Yes
            
            <input type="radio" name="R4" value="No to All">   No to All
            <input type="radio" name="R4" value="No to Some"> No to Some 
            <input name="R4" type="radio" value="Somewhat">Somewhat
            </td> 
          </tr> 
    
    ... etc
    
              <p>
                <input type="submit" value="Submit" name="Submit">
                <input type="reset" value="Reset" name="B2">
              </p>
    
    </form>
    As I said before, I dont care which radio button is selected. Thank you very much for your help!

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this code will check any number of radiao button groups

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>

    <
    script language="JavaScript" type="text/javascript">
    <!--
    var 
    ips,ckd;
    var 
    RadAry=new Array();
    var 
    GrpAry=new Array();

    function 
    CheckRadio(){
     
    ips=document.getElementsByTagName('INPUT');
     
    RadAry=new Array();
     for (
    i=0;i<ips.length;i++){
      if (
    ips[i].type=='radio'){
       
    RadAry[RadAry.length]=ips[i];
      }
     }
     
    GrpAry=new Array();
     
    GrpAry[0]=new Array();
     for (
    i2=0;i2<RadAry.length;i2++){
      
    GrpAry[GrpAry.length-1][GrpAry[GrpAry.length-1].length]=RadAry[i2];
      if (
    RadAry[i2+1]&&RadAry[i2+1].name!=RadAry[i2].name){
       
    GrpAry[GrpAry.length]=new Array();
      }
     }
     for (
    i3=0;i3<GrpAry.length;i3++){
      
    ckd=1;
      for (
    i4=0;i4<GrpAry[i3].length;i4++){
       if (
    GrpAry[i3][i4].checked==true){
        
    ckd=0
       
    }
      }
      if (
    ckd){
       
    alert('Radio Group '+GrpAry[i3][0].name+' is not checked');
      }
     }
    }

    //-->
    </script>
    </head>

    <body>


    <input type="radio" name="fred">
    <input type="radio" name="fred">
    <input type="radio" name="fred">
    <br>
    <input type="radio" name="tom">
    <input type="radio" name="tom">
    <input type="radio" name="tom">
    <br>
    <input type="button" name="" value="Check" onclick="javascript:CheckRadio();">
    </body>

    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:450px;left:0px;" >
    <input size=10 name=Show1 >
    <input size=10 name=Show2 >
    <input size=10 name=Show3 >
    <input size=10 name=Show4 >
    <input size=10 name=Show5 >
    <input size=10 name=Show6 >
    </form>
    </html> 

  5. #5
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple alert windows to single one???

    Thanks a lot for the code. It is great!

    I wonder if it is possible to have one alert window for all validation process? Since I have lots of questions, it will be annoying for the user.

  6. #6
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I got it

    I just changed the last part.

    PHP Code:
     if (ckd){ 
        
    str str 'Radio Group '+GrpAry[i3][0].name+' is not checked\n'
        
      
    }
    }  
    alert(str); 

    Thank you!


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
  •