0

Hi,

I have 6 radio buttons. When I select the radiobutton I need to get the value of the radiobuttons to a php variable. Please help me. I'm new to php.

Thank you in advance

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Utharan
0

Firslty, name each radio button the same and then give each one a different value:

<input type="radio" name="radio_name" value="radio_value1" />
<input type="radio" name="radio_name" value="radio_value2" />
// And so on

Then for the PHP you just need to get the value based on the name:

$radio_value = $_POST['radio_name'];

Obviously change the values in the name and value elements of the radio buttons (and the name of the PHP variable) to what you need them to be.

0

Thanks for your reply simplypixie, but Sorry i forgot to mention another thing. I need the value in the same page. That means in single php page i have the radiobuttons when i select it, it must pass the value to a php variabble without redirecting to another page.

Thankyou

0

Agree with simplypixie,
if to the same page,why not consider using a form and post to self? Another way will be using jQuery.

<input type="radio" class="rdb" name="radio_name" value="radio_value1" />
<input type="radio" class="rdb" name="radio_name" value="radio_value2" />
<div id="text"></div>

jquery code will be

jQuery('.rdb').live('click',function(){
    jQuery('#text').text(jQuery(this).val());
})
0

That makes no difference, you just change the action in the form to submit to the same page (or whichever page your php script is on) - it has nothing to do with the radio buttons.

0

Thank you guys. I have got another way. Thank you very much for your precious time.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.