Nat Posted April 17, 2007 Share Posted April 17, 2007 Hi, I've designed a form that contains some radio buttons and checkboxes. For instance, <p>Size:<br /> <input type="radio" id="sml" name="size" value="Small" /></label for="sml">Small</label><br /> <input type="radio" id="med" name="size" value="Medium" /></label for="med">Medium</label><br /> <input type="radio" id="lge" name="size" value="Large" /></label for="lge">Large</label><br /></p> <p>Colours:<br /> <input type="checkbox" id="green" name="hat[]" value="Green" /><label for="green">Green</label><br /> <input type="checkbox" id="red" name="hat[]" value="Red" /><label for="red">Red</label><br /> </p> Does anyone know how I can assign a dollar value to different options. So that if options are chosen it will calculate the price. For instance a small, red hat would equal different price to a large, green hat. Any guidance would be appreciated I can't find anything anywhere on this topic and I'm so lost. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 17, 2007 Share Posted April 17, 2007 I assume you have the form linked to another page and that you're using the method=post? If so you can either keep your code this way and you'd need an if clause to check what your value of ech button is. But I'd recommend you first change your code into this: <p>Size: <input type="radio" id="size" name="size" value="Small" /></label for="sml">Small</label> <input type="radio" id="size" name="size" value="Medium" /></label for="med">Medium</label> <input type="radio" id="size" name="size" value="Large" /></label for="lge">Large</label> </p> <p>Colours: <input type="checkbox" id="colour" name="hat[]" value="Green" /><label for="green">Green</label> <input type="checkbox" id="colour" name="hat[]" value="Red" /><label for="red">Red</label> </p> That way you'll only be able to select one radio button and you can use an if on your target page to select your values for instance <?php $size = $_GET['size']; $colour = $_GET['colour']; if($size == small) { $price = 10 } and so on, an other solution would be to assign exact values to your radiobuttons for example value="10" that way you could use $_GET on your target page and use the variables immediatly without running them trough an if clause. Quote Link to comment Share on other sites More sharing options...
Dragen Posted April 17, 2007 Share Posted April 17, 2007 I agree with Anzeo. I'd say that using an if clause would be the better way though.. leaving the values at small, large and medium etc. It would make it easier to change it in the future.. instead of having to change the values of all the form elements you'd just need to change it once in each if statement.. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 17, 2007 Share Posted April 17, 2007 Or you could generate your radio buttons with an sql query same thing eventually Quote Link to comment Share on other sites More sharing options...
Nat Posted April 17, 2007 Author Share Posted April 17, 2007 Thank you for the response... That makes sense... But, how would I add the answers of the radio buttons to the answer chosen of the checkboxes? Nat. Quote Link to comment Share on other sites More sharing options...
Anzeo Posted April 17, 2007 Share Posted April 17, 2007 Could you explain a bit more what you mean? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.