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

This question already has an answer here:

  • How can I know which radio button is selected via jQuery? 29 answers

  • 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>
    

    You have to find the checked value of the radio. You're just getting the value of the first radio element.

    How can I know which radio button is selected via jQuery?

    Edit: You also can't use the same ID for every radio button. You'll have to give it a class name or refer to the button by name with jQuery.


    Try this:

    $('input[name=optionu]:checked').val()
    

    Working fiddle here: http://jsfiddle.net/robertrozas/9dYrR/

    链接地址: http://www.djcxy.com/p/24578.html

    上一篇: 如何知道BootStrap单选按钮是否被选中?

    下一篇: 如何使用javescript在PHP中发送单选按钮值?