473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

radio button validation in php?

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

code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $today=date("Y-m-d");
  4. mysql_query("SET CHARACTER SET utf8");
  5. echo "<form method='post' id='submit' action='checkresult.php' dir='rtl'>";
  6. $sql="SELECT * FROM cquestions where showdate='$today' limit 1";
  7. $result=mysql_query($sql);
  8. while ($row = mysql_fetch_array($result)) {
  9. echo "<p>" . $row['cqtext'] . "</p>";
  10. $sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
  11. $result2=mysql_query($sql2);
  12. while($row2=mysql_fetch_assoc($result2))
  13. {
  14. echo "<input type='radio' id='a' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext'];
  15. echo"<br>";
  16. }
  17. }
  18. echo"<br>";
  19. echo"<br>";
  20. echo"<br>";
  21. echo "<div align='left' style='padding-left:160px;'>";
  22. echo"<input type='submit' id='submit' name='submit' value='التالي' />";
  23. echo "</div>";
  24. echo "</form>" ;
  25. ?>
  26.  
in this code it will display a question and 3 answers as radio buttons from a database.

for example
Expand|Select|Wrap|Line Numbers
  1. what is Captial of India?
  2. O New Delhi
  3. O Chennai
  4. O Mumbai
  5.  
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?
Nov 26 '14 #1
1 1631
Luuk
1,047 Expert 1GB
Yes, checking that with JavaScript is possible

see this page
Nov 26 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: tywillia | last post by:
Scenario: There are four questions, each with radio buttons to mark the choice "yes" or "no". I need only one yes per FORM (so if 2 is marked yes, there is no need for any others to be, etc) so...
4
by: TS | last post by:
My objective: To create a survey that asks people to rate a list of things in order of importance. I wish to prevent them from just rating every item in the list the same value. For example the...
3
by: SreeVidya Balasubramanian | last post by:
I am using a set of radio buttons in my asp.net (using C#) application. On click of the submit button i need to confirm whether the radio buttons have been checked using javascript. i am trying to...
5
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button...
2
by: David | last post by:
Hi, I am having a slight problem validating radio buttons using customvalidator. My buttons generated HTML look like... <input id="MemberPage_MinorWorks_SpareLoadYesRadioButton" type="radio"...
0
by: Gary W. Smith | last post by:
Hello, I have a simple form with a radio button group on it and I need to do some basic validation based upon which button is checked. Here is a little more detail. if button one is...
8
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked)...
2
nitindel
by: nitindel | last post by:
Hi all, Greetings... I have to validate the radio buttons that i have used..i mean at least one should be selected and if any one is not selected then it should give an alert and form should...
2
mageswar005
by: mageswar005 | last post by:
I need a radio button empty validation,My radio button is in array . for example: <input type="radio" name="material" >
2
sunsolaris2000
by: sunsolaris2000 | last post by:
A list of courses is displayed and user has to select 1, so I used radio buttons. The course list vary from one student to another. If I have more than 1 courses displayed and user selects one,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.