473,718 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX -- passing on radio button values

2 New Member
I see several postings on this but I am still unable to figure out my problem. I can pass the values of my text field but not radio button (or even checkboxes).

My PHP file

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     //declare our variables
  3.     $day = $_GET['day'];
  4.     $date = $_GET['date'];
  5.     $groupname = $_GET['groupname'];
  6.     $contactperson = $_GET['contactperson'];
  7.     $phonenumber = $_GET['phonenumber'];
  8.     $emailaddress = $_GET['emailaddress'];
  9.     $lengthtime = $_GET['lengthtime'];
  10.     $participants = $_GET['participants'];
  11.     $dvd = $_GET['dvd'];
  12.     $comments = $_GET['comments'];
  13.     $ben = "Ben's";
  14.     $todayis = date("l, F j, Y, g:i a") ;
  15.     $subject = "You have a new TO-GO BOX request from $groupname";                
  16.     $message = " TO-GO BOX REQUEST INFORMATION: \r \n Group Name: $groupname \r Date and Day of pickup: $day on $date \r \n CONTACT PERSON INFORMATION: \r $contactperson \r $phonenumber \r $emailaddress \r \n ACTIVITY INFORMATION: \r Time length of activity: $lengthtime \r Number of participants: $participants \r  DVD: \r $dvd \r \n ADDITIONAL COMMENTS: \r $comments";
  17.  
  18.     //put your email address here
  19.     mail("xxxxxx@xxxxxxxx.org", $subject, $message);
  20. ?>
  21.  
  22.     <h1><span>Thank you  <h3><?php echo $contactperson ?></h3></span></h1>
  23.         <p><span>Your request has been processed.</span></p>
  24.         <p><span>We will see you on your pickup day: <?php echo $day ?>. Thank you!!</span></p>
  25.         <p><span>We are located in xxxxxxxxxxxx</span></p>
  26. <h3>Message sent on: <?php echo $todayis ?></h3>
  27. <a href="javascript:window.close();">
  28.  
  29.  
  30.  
my HTML file

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://www.xxxxxxx.org/jquery.js"></script> 
  4.  
  5. <script type="text/javascript">
  6.  
  7.  
  8.  
  9. $(function() {
  10.     //trigger ajax on submit
  11.     $('#contactForm').submit( function(){
  12.  
  13.         //hide the form
  14.         $('#contactForm').hide();
  15.  
  16.         //show the loading bar
  17.         $('.loader').append($('.bar')); 
  18.         $('.bar').css({display:'block'});
  19.  
  20.         //send the ajax request 
  21.         $.get('mailtogoform.php',{day:$('#day').val(), date:$('#date').val(), groupname:$('#groupname').val(), contactperson:$('#contactperson').val(), phonenumber:$('#phonenumber').val(), emailaddress:$('#emailaddress').val(), lengthtime:$('#lengthtime').val(), participants:$('#participants').val(), dvd:$('#dvd').val(), comments:$('#comments').val()},    
  22.         //return the data
  23.         function(data){
  24.             //hide the graphic
  25.             $('.bar').css({display:'none'}); 
  26.             $('.loader').append(data);  
  27.         });    
  28.  
  29.         //stay on the page                    
  30.         return false;    
  31.     });
  32. });
  33.  
  34.  
  35. </script>
  36.  
  37. <style type="text/css">
  38.  
  39. body {
  40.     font-family:helvetica;    
  41.     background-color: #FF9900;
  42. }
  43.  
  44. .loader {
  45.  
  46. }
  47.  
  48. .bar{
  49.     display:none;    
  50.     background: url('ajax-loader.gif') no-repeat;
  51.     margin-left:20px;
  52.     margin-top:50px;
  53.     height:20px;
  54.     width: 230px;
  55. }
  56.  
  57. #contactForm{
  58.     float:left;    
  59.      position:relative;
  60.     background-color: #ff9900;    
  61.     height: 200px;
  62. }
  63.  
  64. #container {
  65.     padding:20px;
  66.      float:left;    
  67.      position:relative;
  68.      height: 200px;
  69.       width: 100px;
  70. }
  71. .style2 {font-size: 12pt}
  72. .style3 {
  73.     font-family: Arial, Helvetica, sans-serif
  74. }
  75. .style4 {font-size: 10pt}
  76. </style>
  77. </head>
  78.     <body>
  79.     <div class="loader">
  80.     <div class="bar"></div>
  81.     <div id="container">
  82.     <form id="contactForm" method="post" action="mailtogoform.php">
  83.       <table width="100%" border="0" cellspacing="0" cellpadding="0">
  84.         <tr>
  85.           <td width="14%">&nbsp;</td>
  86.           <td width="86%">            <div align="left">
  87.  
  88.  
  89.             <p class="style36 style2 style3"><strong>TO-GO BOX FORM</strong></p>
  90.  
  91.           </div>
  92.  
  93.             <p> <strong>CONTACT DETAILS</strong> </p>
  94.             <p align="left">
  95.                 <label for="groupname"><span class="style4">Group Name</span> </label>
  96.                 <input id="groupname" name="groupname" />
  97.             </p>
  98.             <p align="left">
  99.                 <label for="contactperson"><span class="style4">Contact person</span></label>
  100.                 <input id="contactperson" name="contactperson" />
  101.             </p>
  102.  
  103.             <p align="left">
  104.                 <label for="phonenumber"><span class="style4">Phone Number:</span> </label>
  105.                 <input id="phonenumber" name="phonenumber" />
  106.             </p>
  107.  
  108.             <p align="left">
  109.                 <label for="emailaddress"><span class="style4">Email Address:</span> </label>
  110.                 <input id="emailaddress" name="emailaddress" />
  111.             </p>
  112.             <p> <strong>ACTIVITY DETAILS</strong> </p>
  113.  
  114.  
  115.                     <p align="left">Select a pick-up day:  <br> <br>
  116.                     <input name="day" type="radio" value="Wed 10-3pm">Wed 10-3pm<br>
  117.                     <input name="day" type="radio" value="Thurs 10-3pm">Thurs 10-3pm<br>
  118.                     <input name="day" type="radio" value="Fri 10-7pm">Fri 10-7pm<br>
  119.                     <input name="day" type="radio" value="Sat 10-3pm">Sat 10-3pm<br>
  120.                     <input name="day" type="radio" value="Sun 10-3pm">Sun 10-3pm<br>
  121.                     </p>
  122.  
  123.  
  124.             <p align="left">
  125.                 <label for="date">On what date? (i.e Jan 5, 2009):</label>
  126.                 <input id="date" name="date" />
  127.             </p>
  128.             <p align="left">
  129.                 <label for="lengthtime">Length of bead making activity: </label>
  130.                 <input id="lengthtime" name="lengthtime" />
  131.             </p>
  132.  
  133.             <p align="left">
  134.                 <label for="participants">Number of participants:</label>
  135.                 <input id="participants" name="participants" />
  136.             </p>
  137.  
  138.  
  139.             <p>
  140.             Include DVD?<br>
  141.             <input name="dvd" type="radio" value="Yes" onchange="radio_checker();">Yes<br>
  142.             <input name="dvd" type="radio" value="No" onchange="radio_checker();">No<br>
  143.             </p>
  144.  
  145.  
  146.             <p align="left">    
  147.               <span class="style2">
  148.                 <label for="comments"><strong>ADDITIONAL COMMENTS:</strong> </label>
  149.               </span>
  150.               <textarea id="comments" name="comments" rows="10" cols="90" ></textarea>
  151.             </p>
  152.             <div align="center"> 
  153.         <p><strong>***Your $10 processing fee helps support our <br> 
  154.         &quot;To-Go Box&quot; Program - Thank you! $30 refundable <br> 
  155.     deposit will also be collected at time of pick up*** </strong></p> 
  156.         </div>
  157.             <p align="center">
  158.                 <input class="submit" type="submit" value="submit"/>
  159.             </p>
  160.         </form>        
  161.        </td>
  162.         </tr>
  163.       </table>
  164.     </div>
  165. </body>
  166. </html>
  167.  
  168.  
  169.  
Jan 15 '09 #1
3 6880
acoder
16,027 Recognized Expert Moderator MVP
For radio buttons and checkboxes, get the elements and add the values of the checked ones (find by looping over all the elements).
Jan 15 '09 #2
ToddFur
2 New Member
Uhmmm... Can you point me to an example? Not sure I understand.
Jan 16 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
OK, so let's take the "dvd" radio button:
Expand|Select|Wrap|Line Numbers
  1. var radios = document.getElementsByName("dvd");
  2. // loop over them:
  3. for (i = 0; i < radios.length; i++) {
  4.     if (radios[i].checked) str += "&dvd=" + encodeURIComponent(radios[i].value);
  5. }
Jan 18 '09 #4

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

Similar topics

1
5750
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p align="center"><input class="button" type="button" onClick="location='draftedStory.asp';" value="Click to complete the drafted story"></p> <p align="center"> <input class="button" type="submit" value="Click to view your grade sheet" name="submit"> </p>
2
12346
by: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ... without having to get this value via html, is there any way I can passed the checked value via html .. maybe with syntax like n4.checked.value or something.. Many thanks. <html>
1
1914
by: Dave Harris | last post by:
I am a raw newbie to VB.NET trying to convert a data processing QuickBasic program into .NET. I have about 14 forms, the first of which has a bank of radio buttons identifying the airline. The second bank of radio buttons identifies the aircraft model, and the third bank of radio buttons lets the user choose between two processes. I am using public properties to get and set the values for these three sets of radio buttons. Once these values...
8
4824
by: Midgard | last post by:
Hi, I have this ajax script ajax.js var http_request = false; function update(formid,divid){ document.getElementById(divid).innerHTML="Please wait ..." var form = document.getElementById(formid);
2
6235
by: thanos | last post by:
Hello, How do i pass the value of the radio button to be put of the action that includes the value as part of the URL being submitted - "/ picked.php?pick_num=". Any help with be appreciated. Thanks <form method="post" action="/picked.php?pick_num=".<php? $value ? <input type="hidden" name="cmd" value="0">
1
1675
by: rmeganathan | last post by:
I have problem with passing radio button array in PHP. I am using multiple questions in the same page and each question contains 4 radio button choices. I am using arrary in the form. When I pass the values radio control is not working properly. And also all the questions radio buttons are consideres as one set. (Example 4 question x 4 radio choices = 16 radio buttons. I can select only one outof 16. not 4) Pl give the sample code to solve...
5
14001
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio button? I searched a few things on Google but I find the javascript below most useful in my case but there is some problem that my code is not running: var test = document.getElementsByName("meal"); for (i = 0; i < test.length; i++) {
9
1899
by: Caper | last post by:
Hello everyone, I canít decide which Ajax framework(s) I should take in my project since I am a newbie in the Ajax world. The main task of this project relates to online examining in all middle schools of a province. The structure of each testing paper is rather simple. It contains only 20 to 30 single choice or multiple-choice questions. Once a student finishes a test paper, he or she can press the Submit button to transmit all the...
1
2033
by: ghjk | last post by:
I have a web page developed using php and postgres. There I have a page for user administration(add user). If user fill all information and click submit button I want to send those values to ajax file and validate and insert to the DB. I passed value to the ajax file and I want to send validated values to php file to insert to the DB. How can I do that? Plase help me. This is my php file. if(isset($_POST)){ $array =...
0
8722
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
9352
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
9206
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
9118
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
9052
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5971
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2122
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.