proggR Posted March 27, 2009 Share Posted March 27, 2009 I'm trying to make a pizza ordering form and I want the user to be able to select a radio button of a type of pizza and it will loop through all the toppings checkboxes and leave only the toppings applicable to that type of pizza checked. Furthermore, unless the "custom" radio button is selected, no changes can be made to the checkboxes. I have the radio button call a function onclick and the function gets passed the type's name. I can see, through alerts, that the function is receiving the type successfully. From here I kind of get stuck because I'm not sure how to specify individual checkboxes. The pseudo code would look like. If type equals hawaiin then uncheck all checkboxes of name topping individually check checkbox of name topping who's value is bacon individually check checkbox of name topping who's value is ham individually check checkbox of name topping who's value is pineapple lock checkboxes more ifs for other types if type equals custom clear all checkboxes of name topping unlock checkboxes I'm just not sure how to go about doing that. If anyone could point me in the right direction it would really appreciated. Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/151333-using-javascript-with-checkboxes-and-radio-buttons/ Share on other sites More sharing options...
lonewolf217 Posted March 27, 2009 Share Posted March 27, 2009 couple of examples to get you going. replace the stuff in quotes with your relevant names. also, i suggest you give all of the checkboxes unique names, otherwise you can't pick and choose which ones to select/enable since they will be mutually exclusive <script type="text/javascript"> function selectBoxes() { if(document."formname".getElementById("type").value=='hawaiian') { document."formname"."checkboxname".checked = true; document."formname"."checkboxname".checked = false; } } function enableBox() { document."formname"."checkboxname".disabled = false; } Link to comment https://forums.phpfreaks.com/topic/151333-using-javascript-with-checkboxes-and-radio-buttons/#findComment-795083 Share on other sites More sharing options...
proggR Posted March 27, 2009 Author Share Posted March 27, 2009 I need them to be all of the same name so when it gets passed to my PHP script it can loop through them and add a certain value to the price. The price per topping changes depending on the size of the pizza so I can't just use it as the value either. I'll try out the code you have though. Thank you Link to comment https://forums.phpfreaks.com/topic/151333-using-javascript-with-checkboxes-and-radio-buttons/#findComment-795171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.