How can I send radio button value in PHP using javascript?

vic

I've been at this for week and read all the stackoverflow and google and I can not fix this problem. Every time I test it I get the first radio button no matter which one I click.

What i get in the email is:

Name: test
Email: [email protected]
phone: 9545027557
type: Residential

HTML:

<form name="controls" id="controls"  novalidate>
    <div class="control-group">
        <div class="controls">
            <input type="text" class="form-control" 
                   placeholder="Full Name" id="name" required
                   data-validation-required-message="Please enter your name" />
              <p class="help-block"></p>
        </div>
    </div>  
    <div class="control-group">
        <div class="controls">
            <input type="email" class="form-control" placeholder="Email" 
                   id="email" required
                   data-validation-required-message="Please enter your email" />
        </div>
    </div>  

    <div class="control-group">
        <div class="controls">
            <div class="btn-group" data-toggle="buttons" id="optionu" style="padding-left:25px"> 
                <label class="btn btn-primary active">
                    <input type="radio" class="form-control" id="optionu" name="optionu"
                           value="Residential" checked > Residential 
                </label>
                <label class="btn btn-primary ">
                    <input type="radio" class="form-control" id="optionu" name="optionu"
                           value="Commercial" > Commercial
                </label>
                <label class="btn btn-primary ">
                    <input type="radio" class="form-control" id="optionu" name="optionu"
                           value="Handyman" > Handyman
                </label>
            </div>
        </div>
    </div>
    <p></p>

    <div id="success"> </div> <!-- For success/fail messages -->
    <button type="submit" class="btn btn-danger pull-right">Request</button><br />
</form>

contact_me.js:

var name = $("input#name").val();  
var email = $("input#email").val(); 
var phone = $("input#phone").val(); 
var optionu = $("input#optionu").val();
var firstName = name; // For Success/Failure Message
// Check for white space in name for Success/Fail message
if (firstName.indexOf(' ') >= 0) {
    firstName = name.split(' ').slice(0, -1).join(' ');
}        
$.ajax({
    url: "bin/contact_me.php",
    type: "POST",
    data: {name: name, email: email,  optionu: optionu,  phone: phone},
    cache: false,
    success: function() {  
        // Success message
        $('#success').html("<div class='alert alert-success'>");
        $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
            .append( "</button>");
        $('#success > .alert-success')
            .append("<strong>Your message has been sent. </strong>");
        $('#success > .alert-success')
            .append('</div>');

contact_me.php:

$name = $_POST['name'];
$optionu_value = $_POST['optionu'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];

// create email body and send it
$to = '[email protected]'; // put your email
$email_subject = "Contact form submitted by:  $name";
$email_body = "You have received a new message. \n\n".
              " Here are the details:\n \nName: $name \n  ".
              "Email: $email_address\n phone: $phone\n  type: $optionu";
scx

First of all you use same id 4 times. ID have to be unique in document, you cannot set same id to 4 elements. Also I think the way you are getting value from radio button is wrong.

This is more or less how you can get value from radio button: ( example from another SO question )

  var optionu = $('input[name=optionu]:checked', '#controls').val()

Also remove id from all input[radio] elements.

<label class="btn btn-primary active">
   <input type="radio" class="form-control" name="optionu" value="Residential" checked /> Residential 
 </label>
 <label class="btn btn-primary ">
   <input type="radio" class="form-control" name="optionu" value="Commercial" /> Commercial
 </label>
 <label class="btn btn-primary ">
   <input type="radio" class="form-control" name="optionu" value="Handyman" /> Handyman
 </label>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i keep the radio button checked and get the value

From Dev

How can I check if the returned value of a radio button is empty?

From Dev

How can I bind th:field to value of a radio button in a loop

From Dev

How do I get the value of a radio button in PHP?

From Dev

how to get radio button, checkbox value in csv using ajax and php?

From Dev

How can I add text to radio button with Javascript?

From Dev

How can I set the default radio button using jquery

From Dev

How do I check if a radio button is checked using JavaScript?

From Dev

Can not select the radio button with value using jquery

From Dev

Using the radio button 'checked' value in HTML and PHP

From Dev

How can I get the text of radio button if radio button checked?

From Dev

How do I use a radio button to send a user to a new website in JavaScript?

From Dev

How do i check if a specific Radio button is checked among the other radio buttons using Javascript?

From Dev

how to pass radio button value with jquery & PHP?

From Dev

How to get the value of a radio button in a table - PHP

From Dev

How to pass radio button value with php

From Dev

how to store radio button value in javascript variable?

From Dev

how to get checked radio button value in javascript

From Dev

how get radio button value in javascript

From Dev

How do I get the value of the radio button?

From Dev

how can i clone the radio button?

From Dev

How can I add a class to each radio button of value < current value?

From Dev

How to create radio button dynamically using javascript?

From Dev

Echo radio button value without using submit button in php

From Dev

How to send the checked radio button value to Server in angular js

From Dev

how to send multiple radio button values via ajax to php

From Dev

How can I send the value of the id through ajax and PHP

From Dev

How can I send a null value to a stored procedure using SqlParameter?

From Dev

how can i get value of textbox on radio button's change event in cloning?

Related Related

  1. 1

    How can i keep the radio button checked and get the value

  2. 2

    How can I check if the returned value of a radio button is empty?

  3. 3

    How can I bind th:field to value of a radio button in a loop

  4. 4

    How do I get the value of a radio button in PHP?

  5. 5

    how to get radio button, checkbox value in csv using ajax and php?

  6. 6

    How can I add text to radio button with Javascript?

  7. 7

    How can I set the default radio button using jquery

  8. 8

    How do I check if a radio button is checked using JavaScript?

  9. 9

    Can not select the radio button with value using jquery

  10. 10

    Using the radio button 'checked' value in HTML and PHP

  11. 11

    How can I get the text of radio button if radio button checked?

  12. 12

    How do I use a radio button to send a user to a new website in JavaScript?

  13. 13

    How do i check if a specific Radio button is checked among the other radio buttons using Javascript?

  14. 14

    how to pass radio button value with jquery & PHP?

  15. 15

    How to get the value of a radio button in a table - PHP

  16. 16

    How to pass radio button value with php

  17. 17

    how to store radio button value in javascript variable?

  18. 18

    how to get checked radio button value in javascript

  19. 19

    how get radio button value in javascript

  20. 20

    How do I get the value of the radio button?

  21. 21

    how can i clone the radio button?

  22. 22

    How can I add a class to each radio button of value < current value?

  23. 23

    How to create radio button dynamically using javascript?

  24. 24

    Echo radio button value without using submit button in php

  25. 25

    How to send the checked radio button value to Server in angular js

  26. 26

    how to send multiple radio button values via ajax to php

  27. 27

    How can I send the value of the id through ajax and PHP

  28. 28

    How can I send a null value to a stored procedure using SqlParameter?

  29. 29

    how can i get value of textbox on radio button's change event in cloning?

HotTag

Archive