Jump to content

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.

 

Link to comment
https://forums.phpfreaks.com/topic/129947-problem-with-listmenu-field/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.