dc_jt Posted November 7, 2006 Share Posted November 7, 2006 Hi I have a list of categories.If a user clicks a certain category, they are taken to a form where they can add a listing to that category. In this form, all categories are listed as checkboxes for example hotels, bars, restaurants. If the user selected the hotel category orginally, how can the hotel checkbox be automatically ticked, representing this categofy they are in?Thanks Quote Link to comment Share on other sites More sharing options...
blear Posted November 7, 2006 Share Posted November 7, 2006 This is all JavaScript functionality you're looking for here. Try looking at JavaScript topic "onClick" . Quote Link to comment Share on other sites More sharing options...
Kelset Posted November 8, 2006 Share Posted November 8, 2006 Name all the checkboxes the same and then loop through them to see what ones have been checked.Name them all something like this[code]<INPUT TYPE='checkbox' NAME='cat[]' value='hotel'><INPUT TYPE='checkbox' NAME='cat[]' value='bars'><INPUT TYPE='checkbox' NAME='cat[]' value='restaurants'>[/code]This will put all the checkboxes into an array when form is submitted, array name being cat.On the page where you want the checkbox ticked you just use a for loop.[code]if(in_array("hotel",$cat)) { $hotel_check = "checked";}else{ $hotel_check = "";}if(in_array("bars",$cat)) { $bars_check = "checked";}else{ $bars_check = "";}if(in_array("restaurants",$cat)) { $restaurants_check = "checked";}else{ $restaurants_check = "";}[/code]Then have the checkbox HTML look something like this[code]<INPUT TYPE='checkbox' NAME='cat[]' value='hotel' <?PHP echo $hotel_checked; ?>><INPUT TYPE='checkbox' NAME='cat[]' value='bars' <?PHP echo $bars_checked; ?>><INPUT TYPE='checkbox' NAME='cat[]' value='restaurants' <?PHP echo $restaurants_checked; ?>>[/code]This is just from the top of my head and nothing is tested, I'm sure there is a better way to do the if statments buti'm new. Sorry for not being able to optomized better but like I said I'm a newb :)Hope I was of some helpCheers!Stephen 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.