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
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.
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
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());
})
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.
Thank you guys. I have got another way. Thank you very much for your precious time.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.