fife Posted February 14, 2011 Share Posted February 14, 2011 Hi. I have two select fields one called category and the other sub category. Both are in the format. <select name="category" value=" <?php $qGetCat = "SELECT * FROM club_category" ; $rGetCat = mysql_query($qGetCat); while ($Cat = mysql_fetch_assoc($rGetCat)) { ?>" /> <option value="<?php echo $Cat['categorys'];?>"><?php echo $Cat['categorys']; ?></option> <?php } ?> </select> <select name="sub_category" value=" <?php $qGetSubCat = "SELECT * FROM sub_categorys" ; $rGetSubCat = mysql_query($qGetSubCat); while ($SubCat = mysql_fetch_assoc($rGetSubCat)) { ?>" /> <option value="<?php echo $SubCat['sub_categorys'];?>"><?php echo $SubCat['sub_categorys']; ?></option> <?php } ?> </select> Now I want to make it so that when a particular category is chosen for example self defence. The sub category when clicked shows all the self defence stuff. If watersports was chosen sub category would show things like swimming. What do I need to look up to do this? At the minute there is no link the way I have coded these to fields. In the database its self there is a; category table with categoryID and category_name sub category table with sub_cat_name and categoryID I think this will work but I have never done this so its making my head hurt just thinking about it. Does anyone have any advice, tuts or scripts to do this? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/227635-select-field-question/ Share on other sites More sharing options...
BlueSkyIS Posted February 14, 2011 Share Posted February 14, 2011 2 options, both involving javascript: 1. add onchange event to first selection to submit the form and populate the 2nd select or 2. add onchange event to first selection to use ajax to populate the 2nd select Quote Link to comment https://forums.phpfreaks.com/topic/227635-select-field-question/#findComment-1174080 Share on other sites More sharing options...
fife Posted February 14, 2011 Author Share Posted February 14, 2011 thank you I will hunt these down now Quote Link to comment https://forums.phpfreaks.com/topic/227635-select-field-question/#findComment-1174084 Share on other sites More sharing options...
Pikachu2000 Posted February 14, 2011 Share Posted February 14, 2011 FYI: the markup is not valid. <select> tags do not get a value= attribute, just a name= attribute. Only the <option> tags get a value= attribute. Quote Link to comment https://forums.phpfreaks.com/topic/227635-select-field-question/#findComment-1174158 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.