sandhya Posted October 24, 2008 Share Posted October 24, 2008 hi all, i'm confused with this. i'm developing a form by getting data from mysql database. i have two list/menu fields. first field displays the main categories from the database. and the second one displays the subcategories of the selected category from first menu. up this every thing is fine. after selecting the category wrote a function to submit the form. and after reloading the category should be selected automatically from the following code written after while loop. <? if($_POST['cat']!="") { ?> <script language="javascript"> var catg=<? echo $_POST['cat'] ?>; var i; for(i=1;i<=document.form1.cat.options.length;i++) { if(document.form1.cat.options.value==catg) { document.form1.cat.options.selected=true; } } </script> <? } ?> it was working nice for this. but after selecting subcategory also submitting the form and after reloading subcategory field also should be selected automatically same as the category field.but here some problem is arising. it selects the default field from the list.i wrote similar code as for first one. i'm giving the second one's code also. <? if($_POST[subcat]!="") { echo "subcat=".$_POST[subcat]; ?> <script language="javascript"> var subcatg=<? echo $_POST[subcat] ?>; for(i=1;i<=document.form1.subcat.options.length;i++) { if(document.form1.subcat.options.value==subcatg ) { document.form1.subcat.options.selected=true; } } </script> <? } ?> please anyone help me. thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/129947-problem-with-listmenu-field/ Share on other sites More sharing options...
sandhya Posted October 25, 2008 Author Share Posted October 25, 2008 please tell me what is happening there and how to solve it. Quote Link to comment https://forums.phpfreaks.com/topic/129947-problem-with-listmenu-field/#findComment-674232 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.