Skip to main content
Participating Frequently
February 22, 2010
Question

Radio Buttons w/ Multiple Values on a PHP Form

  • February 22, 2010
  • 1 reply
  • 1908 views

Hi,

I have an Online Registration form with several options that each have their own prices.  I want the form results to show the name of each option the user selects, and the total of all the prices combined.  My question is how can I do that when each radio button only allows you to attach one value?  Is there a way to somehow retrieve the option name and price as two separate values?

<input name="option" type="radio" value="Cotton - $10" />

<input name="option" type="radio" value="Suede - $15" />

<input name="option" type="radio" value="Leather - Black - $20" />

<input name="option" type="radio" value="Leather - White - $20" />

For example, if they select 'Leather - Black - $20" I want to be able to retrieve one value of "Leather - Black" and another value of "20.00" (to add to the total price) rather than simply "Leather - Black - $20" in one value.

Any help would be greatly appreciated!  I've only had to deal with one value for each radio button in the past.

Thanks!

Paul

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
February 22, 2010

No, a radio button can have only one value.

Use conditional logic in your processing to assign the price.

switch ($_POST['option') {

  case 'Cotton':

    $price = 10;

    break;

  case 'Suede':

    $price = 15;

    break;

  default:

    $price = 20;

}

David_Powers
Inspiring
February 22, 2010

I have just noticed that you posted an identical question in the main Dreamweaver forum, but didn't have the courtesy to mark this question as answered. Thanks for wasting my time.

Please do not post the same question in more than one forum. If you do, have the decency to follow up in all forums to say that your question has been answered.

pbsum83Author
Participating Frequently
February 22, 2010

I didn't mark it answered because it wasn't.  You actually answered my question correctly though, which I really appreciate.  Thanks a lot!  I posted the same thing on both forums, because I figured I would get more response, which is exactly what happened.  Sorry if I hit a sensetive spot, but had I marked that thread as answered, I wouldn't have recieved your answer, which is much more what I was looking for.

Thanks, and have a great day.

Paul