Tuesday, May 15, 2012
Java Script - validate Form multiple Radio button field with php
Java Script - validate Form multiple Radio button field with php
========================================
<head>
<script type="text/javascript">
function validateFormRadioButton()
{
if ((document.quizForm.optn[0].checked == false) &&
(document.quizForm.optn[1].checked == false) && (document.quizForm.optn[2].checked == false) &&
(document.quizForm.optn[3].checked == false))
{
alert("Please select any answer ");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form id="form_406085" name="quizForm" class="appnitro" method="post" action="quiz_submit.php" onsubmit="return validateFormRadioButton();">
<?php
require('db/sqlquery.php');
while($ib_row = mysql_fetch_array($row))
{
// Radio Button for Option1
echo "<input id=\"element_18_1\" name=\"optn\" class=\"element radio\" type=\"radio\" value=\"option1\" />";
echo "<label class=\"choice\" for=\"element_18_1\">";
// radio button value comes from mysql
echo $ib_row['option1'];
echo "</label>";
// Radio Button for Option2
echo "<input id=\"element_18_2\" name=\"optn\" class=\"element radio\" type=\"radio\" value=\"option2\" />";
echo "<label class=\"choice\" for=\"element_18_2\">";
// radio button value comes from mysql
echo $ib_row['option2'];
echo "</label>";
// Radio Button for Option3
echo "<input id=\"element_18_4\" name=\"optn\" class=\"element radio\" type=\"radio\" value=\"option3\" />";
echo "<label class=\"choice\" for=\"element_18_3\">";
// radio button value comes from mysql
echo $ib_row['option3'];
echo "</label>";
// Radio Button for Option4
echo "<input id=\"element_18_4\" name=\"optn\" class=\"element radio\" type=\"radio\" value=\"option4\" />";
echo "<label class=\"choice\" for=\"element_18_3\">";
// radio button value comes from mysql
echo $ib_row['option4'];
echo "</label>";
?>
</form>
</body>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment