radio button validation in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • impin
    New Member
    • Jul 2010
    • 127

    radio button validation in php?

    how to validate the radio buttons. at least one options is selected.

    code:
    Code:
    <?php
    
    $today=date("Y-m-d");
    mysql_query("SET CHARACTER SET utf8");
    echo "<form method='post' id='submit' action='checkresult.php' dir='rtl'>";
    $sql="SELECT * FROM cquestions where showdate='$today' limit 1";
    $result=mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
    echo "<p>" . $row['cqtext'] . "</p>";
    $sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
    $result2=mysql_query($sql2);
    while($row2=mysql_fetch_assoc($result2))
    {
    echo "<input type='radio' id='a' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext'];
    echo"<br>";
    }
    }
    echo"<br>";
    echo"<br>";
    echo"<br>";
    echo "<div align='left' style='padding-left:160px;'>";
    echo"<input type='submit' id='submit' name='submit' value='التالي' />";
    echo "</div>";
    echo "</form>" ;
    ?>
    in this code it will display a question and 3 answers as radio buttons from a database.

    for example
    Code:
    what is Captial of India?
    O New Delhi
    O Chennai
    O Mumbai
    user has to select a correct answer. if the user not selecting any answer and click submit, I want to show a message "please select answer the question".?

    how to do it?

    can we use javascript?
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    Yes, checking that with JavaScript is possible

    see this page

    Comment

    Working...