473,805 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ 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 4527
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
1768
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"), but I also have another value which needs to be carried (2 values per radio button), RS("PSL_L_Serial").
4
2582
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 multiple records and want two values depending on the row they select. slaveform: x=selected
6
3945
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 would prefer a generic script to do this. I had no problems with the script until I had to deal with the radio elements. Following is the problem part of the code: function resetFields() {
3
2834
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" name="group1" value="3" label="Cheese" checked>Cheese<br>
1
47855
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 radio button is selected and store the value (1, 2 or 3) in a Byte variable. Now, I assumed that this was a simple case of choosing the button you wanted and checking the fraSearchMode.Value property for value 1, 2 or 3. Apparently this is not so....
4
9906
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 string representing radio button values. Thanks, -hazz
5
2156
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 always shows the value =1 instead the values selected under my radio buttons (Values= 4,3 or 1) I am showing the code. Ideas welcome.
2
12443
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 into converting into code.
1
1847
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 convert the values to numeric in JS.. pls help me I am stuck..i hv pasted the code below: ******************************** <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId"...
8
2983
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 box with values too. Depending on the options selected from the two, the values will be calculated and displayed. everything worked fine with the calculation and im getting the right amount totalled up. I only have one issue, whenever the radio...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10607
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
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 we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.