0

Hi Guys,

As part of an online store, I have a dropdown box where the user selects a size. If the user selects size L then the 'add to cart' button needs to link to a page different than if the user selected size M.

I figured out that I can only grab the selected value for PHP to process if it was submitted, i.e., through a form. Then I could do something like this:

if($_POST['dropdown'] == 'M') {
  $product = 'link';
} else if {
  //do something else
}

But I am not sure if this is possible using a button... I'm still a beginner here, but any thoughts?

Edited by James_43

3
Contributors
3
Replies
18
Views
2 Years
Discussion Span
Last Post by James_43
0

You can have a bank of buttons (like radio buttons). However, I'm unsure why you'd want to link to a different 'page'. I'd have thought that size was just a property of the product, just some piece of data to be carried on with the product_id.

<label><input type="radio" name="size" value="S" checked />S</label>
<label><input type="radio" name="size" value="M" />M</label>
<label><input type="radio" name="size" value="L" />L</label>
<label><input type="radio" name="size" value="XL" />XL</label>

Always make sure you have a default checked, otherwise errors can ensue if a user submits without checking a size.

Then you pick it up as:

$size = $_POST['size'];
$product_id = $_POST['product_id'];
$quantity = $_POST['quantity'];

These would require validation.

Of course, most baskets are 'ajaxed', so that you don't lose the page you're on and the item appears 'magically' in the basket, e.g. "BASKET Items: 3"

The HTML given will give you radio buttons, which visual-wise may not be what you want, BUT there are many, many CSS snippets that can give them the appearance of buttons. Sorry, can't help further off on vacation.

0

maybe using a <select><option> was what you wish for, by using then onchange event from to select box using jquery/javascript, you can easily change the form's attribute. You may even prevent default action from the form submit using jquery function and based on the user's selection and then submit the form using jquery.

0

Cheers guys. I was looking at this fairly weirdly, but have manage to sort just by using the form info :)

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.