473,468 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to get the values of a radio button

7 New Member
i have a set of radio buttons generated inside a loop then i append a variable from the loop to the name of the radio button and to the value. the question is, how do i get the value of the radio button being selected. here's a short code..

<?php
for($i=1; $i<=5; $i++){
echo "<input type = 'radio' name=q$i value = \'$i\'>";
}
?>
Feb 3 '08 #1
2 4505
Markus
6,050 Recognized Expert Expert
i have a set of radio buttons generated inside a loop then i append a variable from the loop to the name of the radio button and to the value. the question is, how do i get the value of the radio button being selected. here's a short code..

<?php
for($i=1; $i<=5; $i++){
echo "<input type = 'radio' name=q$i value = \'$i\'>";
}
?>
You can use foreach() to traverse through the radio buttons, then use isset() to see which was selected.

[php]
<?php
foreach($_POST['radio'] as $_val)
{
if(isset($_POST['radio']))
{
echo "Selected: $_val ";
}
}
?>
[/php]
Feb 3 '08 #2
ifedi
60 New Member
i have a set of radio buttons generated inside a loop then i append a variable from the loop to the name of the radio button and to the value. the question is, how do i get the value of the radio button being selected. here's a short code..

<?php
for($i=1; $i<=5; $i++){
echo "<input type = 'radio' name=q$i value = \'$i\'>";
}
?>
How do you get the value of the radio group?

The VALUE attribute of the SELECTED radio option is carried over as part of the POST data:
e.g. when the form is submitted, $_POST['radioname'] would have a value equal to the VALUE of the radio option that was selected.
In order to work well, all the input elements must be given the same NAME; to identify each option uniquely, use an ID attribute.
To use your example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     for($i=1; $i<=5; $i++){
  3.         echo "<input type = 'radio' name='q' id='q$i' value = \'$i\'>";
  4.     }
  5. ?>
After submitting the form, $_POST['q'] would have a possible value of 1-5, depending on the option selected.

Please, let me know if this helps.

Regards,
Ifedi.
Feb 8 '08 #3

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

Similar topics

1
by: David | last post by:
Hi, I have an ASP page with a form and the following code: ..... type=Radio Checked name=selectserial value=" & RS("PSL_F_Serial")..... Tis will carry over the value of RS("PSL_F_Serial"),...
4
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through...
6
by: Tyrone Slothrop | last post by:
I am coding a search form which carries the values to an identical form on the search results page. A "Clear Fields" button to remove the values from the previous search is required. Ideally I...
3
by: lee | last post by:
Hello I need some javascript code I've written to handle 2 values from an HTML form. I've been successful using the "label" attribute (I've simplied the example below): <input type="radio"...
1
by: Rage Matrix | last post by:
Hi all, I have a small problem with Access radio button groups in VBA. I've got a radio button group called fraSearchMode with three radio buttons in it. At a certain point, I want to see which...
4
by: Hazzard | last post by:
What is the best way to do this? Binary with 0 representing off and 1 on? Int16 with 1 representing first button, 2 the second, 3 ... varchar with a character values at certain positions in the...
5
by: Mirovk | last post by:
The onclick action associated to my form´s radio buttons call to a vbscript were the session values are changed, this happens correctly but with the onclick action associated to my continue button...
2
by: Eric Layman | last post by:
Hi, I have a radio button and a combo box. Upon changing a value for radio button, the combo box values will be dynamically updated. I have an idea on how to go abt doing it but Im stuck...
1
by: Renjini Mary | last post by:
hi... i cant seem to get value of set of radio buttons thru javscripting.. i hv set values to the radiobuttons but cannot retrieve them or calculate them in JS although it looks simple. do i need to...
8
by: crayfiss | last post by:
Hi, firstly I am a total freshie in all this. From what I have gathered on the web and this forum, I finally managed to get my form up. I have a set of radio buttons with values to it and a select...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.