PHP - javascript validation radio button
        Posted  
        
            by 
                user1806136
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1806136
        
        
        
        Published on 2012-11-16T04:52:43Z
        Indexed on 
            2012/11/16
            5:00 UTC
        
        
        Read the original article
        Hit count: 186
        
i have a form with 3 sets of radio buttons. i want to set a simple javascript validation alert to appear when user clicks on submit when one of the fields is null. how can i do that using javascript ?
my code so far is ..
<?php
       session_start();
       $Load=$_SESSION['login_user'];
       include('../connect.php');
                    if (isset($_POST['submit']))
    {  
       $v1 = intval($_POST['v1']);
       $v2 = intval($_POST['v2']);
       $v3 = intval($_POST['v3']);
       $total = $v1 + $v2 + $v3  ;
     mysql_query("INSERT into Form1 (P1,P2,P3,TOTAL)
     values('$v1','$v2','$v3','$total')") or die(mysql_error());
     header("Location: mark.php");
     }
  <center><form method="post" action="mark.php"  >
        <tr>
<th > School Evaluation <font size="4" > </font></th>
<tr>
<th > Criteria <font size="4" > </font></th>
            <th> 4<font size="4" > </font></th>
            <th> 3<font size="4" > </font></th>
            <th> 2<font size="4" > </font></th>
            <th> 1<font size="4" > </font></th>
        </tr>
<tr>
<th> Your attendance<font size="4" > </font></th>
<td>  <input type="radio" name ="v1" value = "4"    onclick="updateTotal();"/></td>
<td>  <input type="radio" name ="v1" value = "3"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v1" value = "2"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v1" value = "1"    onclick="updateTotal();" /></td>    
</tr>
<tr>
<th > Your grades  <font size="4" > </font></th>
<td>  <input type="radio" name ="v2" value = "4"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v2" value = "3"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v2" value = "2"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v2" value = "1"    onclick="updateTotal();" /></td>    
</tr>
<tr>
<th >Your self-control <font size="4" > </font></th>
<td>  <input type="radio" name ="v3" value = "4"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v3" value = "3"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v3" value = "2"    onclick="updateTotal();" /></td>
<td>  <input type="radio" name ="v3" value = "1"    onclick="updateTotal();" /></td>    
</tr>       
        </tr>
    </table>
i have put
<br>
        <td><input type="submit" name="submit" value="Submit" onClick="return validation(form);">
        <input type="reset" name="clear" value="clear" style="width: 70px"></td>
     </form> 
i have try alot of codes but no alert appears!
© Stack Overflow or respective owner