Jump to content
#StayAtHome ×

Archived

This topic is now archived and is closed to further replies.

sandhya

problem with list/menu field.

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.