473,545 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

append a loop variable in a radio button name

7 New Member
I used the for loop variable $i to each radio button so that each radio button will have a unique name. the problem now is how can i display the values selected in the radio button on the same page as where the form is located.
your help is greatly appreciated.. thanks
here's the code:
NOTE: this code is cut short, i only posted the part where i got stuck
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         if(isset($_GET['sub'])){
  3.             $num = $_GET['num'];
  4.             $num = 2;
  5.             for($i=1; $i<=$num; $i++ ){
  6.                 echo '
  7.                 <tr>
  8.                     <td align="center">
  9.                         Question no.: '.$i.'
  10.                         <br>
  11.                         A.<input type="radio" name="'.$i.'[]"   
  12. value="A"><br>
  13.                         B.<input type="radio" name="'.$i.'[]" value="B"><br>
  14.                         C.<input type="radio" name="'.$i.'[]" value="C"><br>
  15.                         D.<input type="radio" name="'.$i.'[]" value="D"><br>
  16.                     </td>
  17.                 </tr>';
  18.             }
  19.         }
  20.         if($_GET['eva']){
  21.             $choice = $_GET['$i']; //this is where i got stuck
  22.             foreach($choice as $opt){
  23.                 echo $opt;
  24.             }
  25.         }
  26.     ?>
  27.     <tr>
  28.         <td align="center">
  29.             <input type="submit" name="eva" value="evaluate">
  30.         </td>
  31.     </tr>
Feb 2 '08 #1
8 6754
harshmaul
490 Recognized Expert Contributor
Hi,
A few problems with yout mark up....
the radio buttons need to be in a group with the SAME name. the whole thing about radio buttons is that they are grouped together, (eg. male female, single married). if you want them to be selected individualy you will need to use a "checkbox".

But back to your problem so having given your radio buttons a static name you can get it from the forms method variable but only on the post back.

If your like me i can understand code better than conversation so here is some code....

The HTML
Expand|Select|Wrap|Line Numbers
  1. A.<input type="radio" name="'myradioButton" value="A">A<br>
  2. B.<input type="radio" name="'myradioButton" value="B">B<br>
  3. C.<input type="radio" name="'myradioButton" value="C">C<br>
The PHP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (IsSet($_GET("myradioButton")){
  3. ?>
  4. the value of the radio buttons was....<?php echo $_GET("myradioButton"); ?>
  5. <?php } ?>
Feb 2 '08 #2
romano2717
7 New Member
Hi,
A few problems with yout mark up....
the radio buttons need to be in a group with the SAME name. the whole thing about radio buttons is that they are grouped together, (eg. male female, single married). if you want them to be selected individualy you will need to use a "checkbox".

But back to your problem so having given your radio buttons a static name you can get it from the forms method variable but only on the post back.

If your like me i can understand code better than conversation so here is some code....

The HTML
Expand|Select|Wrap|Line Numbers
  1. A.<input type="radio" name="'myradioButton" value="A">A<br>
  2. B.<input type="radio" name="'myradioButton" value="B">B<br>
  3. C.<input type="radio" name="'myradioButton" value="C">C<br>
The PHP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (IsSet($_GET("myradioButton")){
  3. ?>
  4. the value of the radio buttons was....<?php echo $_GET("myradioButton"); ?>
  5. <?php } ?>

the problem is i dont know how to get the values of the selected radio buttons since the name of each radio buttons has a variable appended to it. can anyone help me with this?
Feb 3 '08 #3
Markus
6,050 Recognized Expert Expert
Well don't give a unique name to the input.

name="something[]"

Will do just fine.
Feb 3 '08 #4
romano2717
7 New Member
Well don't give a unique name to the input.

name="something[]"

Will do just fine.
but i need to have a unique name for each set of radio buttons, so for every loop it will create four radio buttons with unique names.
Feb 5 '08 #5
harshmaul
490 Recognized Expert Contributor
Hi,
are the radio button mutually exclusive to eachother? or do you want them grouped together?
Feb 5 '08 #6
romano2717
7 New Member
Hi,
are the radio button mutually exclusive to eachother? or do you want them grouped together?
i want them grouped together so i will have a set of radio buttons consist of four radio buttons.. imagine an exam.. you have 5 questions with 4 choices each, so each question which is consist of 4 choices you can only select one radio button each question.
Feb 6 '08 #7
harshmaul
490 Recognized Expert Contributor
Hi,
Refer to my previous post.

All the ones in the same "answer" for the question will need the same name like question1, and the value between the tags will be the value displayed and posted back to the server. if you post all relevent code i will show you.
Feb 6 '08 #8
i have the same problems. is there any solutions? thanks
Sep 27 '10 #9

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

Similar topics

4
3261
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
33
3623
by: Brian | last post by:
I have a list of plain HTML radio buttons that I want to be able to loop through, get the values from them and insert them into a db. each one should be a separate record... Can anyone please give me some kind of example on how to do this???? I am doing this in asp.net VB. Please let me know if you need any additional information. Thanks
3
3841
by: B-Dog | last post by:
I'm capturing the checked radio button to XML file using the name of the radio button. I want to read my xml file to find which button was checked on close and the check the appropriate button when for loads. How do I use a variable control name. This is what I'm trying to do below but of course it doesn't work, I'm rookie. Thanks ...
6
1662
by: Ed Jay | last post by:
<disclaimer>New to js.</disclaimer> I have several pages, each with menues comprising checkboxes or radio boxes within the same form. I presently 'brute force' clear the buttons with individual scripts for each form, e.g.: function clearLa() { window.document.form1.button1La.checked=false; window.document.form1.button2La.checked=false;...
2
3396
by: Mirovk | last post by:
Hi, I have a session variable wich value arrives from a previous .asp but in my actual page I need to modify it based upon a selected value from a radio button. I will try to figure out for better understanding: page1.asp ---session("PaymentMethod") page2.asp ---Depending on the radio button selected the payment
9
9295
by: wreed | last post by:
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements.type; if (temp == "radio") { for (x = 0; x < the_form.elements.length - 1; x++) {
9
2224
by: IchBin | last post by:
I can not see what the problem is with this script. I am just trying to set a radio button by calling setCheckedValue('abbr_letter', 'V'). Sorry I am new to javascript. <html> <head> <script type="text/javascript"> function setCheckedValue(radioObj, newValue) { if(!radioObj)
10
6056
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
2
21398
by: somacore | last post by:
VS2005, C# Windows Form I can't quite figure out how to do this, but i think I'm close. I have a groupbox which contains 8 radio buttons, and I need to figure out which one is checked for entry into a database. The button field looks like this: ()Assigned ()Working ()In Testing and so on. In the DB, the values of the checkboxes...
0
7490
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
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. ...
0
7935
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...
0
7780
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6009
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...
1
5351
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...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1911
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
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.