Hi, I'm making an advanced search form and I wish the users to be able to select a category frmo a static list which lists all the categories, When this category is selected a dynamic form list will appear showing all the subcategories in that category. There is a good example on: http://www.mininova.org/upload But how would I go about doing this? Thanks in advance
That will be fairly simple. You need to create a DIV and populate its innerHTML property with new combo as per parent's selected item. Or hide all and show the one needed. Let me know if you need example. regards
Are you using PHP as server-end language ? So that I can provide script that can generate required thingy dynamicaly. regards
Ok, try this boy, save following code as html file on desktop and try: <script> var sub_categories = new Array( //categories under Animals new Array('Cat', 'Dog', 'Elephant'), //categories under Strange Creatures new Array('Mermaid', 'Unicorn', 'Medusa') ) function populate(main_id,combo_name) { var arr = sub_categories[main_id-1]; var htm = "<select name='"+combo_name+"'>"; for(var i=0; i<arr.length; i++) { htm = htm + "<option>" + arr[i] + "</option>"; } document.getElementById('subdiv').innerHTML = htm; } </script> <table border="1"> <tr> <td> <select name=main id=main onChange="javascript:populate(this.value, 'cat_id')"> <option value='0'>Select Category</option> <option value='1'>Animals</option> <option value='2'>Strange Creatures</option> </select> </td> <td> <div id="subdiv">None selected</div> </td> </tr> </table> Code (markup): I hope it helps. regards
Could you have a look at the code i've made please? I'm getting javascript errors so something must be wrong. http://danthorpe.co.uk/advancedsearch.txt
Rightnow, moving to bed , really tired, will provide you full php based example when I wake up (for sure). regards