Jump to content

Hide/ Unhide Menu Help


hane

Recommended Posts

After searching the web the web the whole day I finally found what i think I'm looking for. The only problem is I dont know JS and the code that I found doesnt want to work and I need someone to look at it for me so that I can start playing with it and see if I can make it fit into what I need. What I need is a drop down when I select option it un hides the search menu for a category. I have 3 categories: Directory, Classifieds and Smalls. Each have their own working dynamic populated search menu from mysql.here is the code that i found:

<script type="text/javascript">//select funtion// I had to hide both drop down boxes before I showed the visible one // otherwise it would not erase the previos box thus starting with a clean // pagefunction select(){sel = document.close.status;if (sel.options[sel.selectedIndex].value == 'Closed'){sel1.style.visibility = "hidden";sel2.style.visibility = "hidden";sel1.style.visibility = "visible";}else if (sel.options[sel.selectedIndex].value == 'Re-Assign'){sel1.style.visibility = "hidden";sel2.style.visibility = "hidden";sel2.style.visibility = "visible";}else{sel1.style.visibility = "hidden";sel2.style.visibility = "hidden";}}</script<table><tr><td align="right"><strong>Change Status To:</strong></td><td align="left"><select name="status" style="WIDTH: 125px" onChange="select()"><option value="" selected=""></option><option value="Closed">Closed</option><option value="Re-Assign">Re-Assign</option></select></td></tr></table><div id="sel1" STYLE="position:absolute; top: 348px; right: 215px; visibility:hidden;"><table><tr><td align="right"><strong>Closed By:</strong></td><td><select name="closed_by" style="WIDTH: 125px"><option value="" selected=""></option><OPTION value="dude">dude</option><OPTION value="dude1">dude1</option><OPTION value="dude2">dude2</option><OPTION value="dude3">dude3</option></select></td></tr></table></div><div id="sel2" STYLE="position:absolute; top: 348px; right: 215px;visibility:hidden;"><table><tr><td align="right"><strong>Re-assigned to:</strong></td><td><select name="reassigned_to" style="WIDTH: 125px"><option value="" selected=""></option><OPTION value="dude">dude</option><OPTION value="dude1">dude1</option><OPTION value="dude2">dude2</option><OPTION value="dude3">dude3</option></select></td></tr></table></div>

Help would really be appreciated. Thanks

Link to comment
Share on other sites

Hi, the only thing that doesn't seem right (for now) is:function select(){sel = document.close.status; <--- this onechange it to sel = document.getElementById('status');and add:<select name="status" id="status" style="width: 125px" onChange="select()">to the first select.hope this helps.

Link to comment
Share on other sites

Thanks for all the help here is the code that I came up with. It works 99% i just need some more help with the 1% please. :). When I select the first option eg. Directory the directory menu comes up but here is the problem when I select the directory category the page reloads and populates the subcategory. Now on reload the directory menu is hidden. I want it to be unhidden Please help :)

<script type="text/javascript">//select funtion// I had to hide both drop down boxes before I showed the visible one // otherwise it would not erase the previos box thus starting with a clean // pagefunction select(){sel = document.getElementById('data');if (sel.options[sel.selectedIndex].value == 'classified'){sel1.style.visibility = "hidden";sel2.style.visibility = "hidden";sel1.style.visibility = "visible";}else if (sel.options[sel.selectedIndex].value == 'directory'){sel1.style.visibility = "hidden";sel2.style.visibility = "hidden";sel2.style.visibility = "visible";}else{sel1.style.visibility = "hidden";sel2.style.visibility = "hidden";}}</script<table><tr><td align="left"><select name="data"  id="data" style="WIDTH: 125px" onChange="select()"><option value="" selected="">Select</option><option value="classified">Classified</option><option value="directory">Directory</option></select></td></tr></table><div id="sel1" STYLE="visibility:hidden;"><!--table><tr><td align="left"><select name="classified" style="WIDTH: 125px"><option value="" selected=""></option><OPTION value="dude">dude</option><OPTION value="dude1">dude1</option><OPTION value="dude2">dude2</option><OPTION value="dude3">dude3</option></select></td></tr></table--><script language=JavaScript>function reload(form){var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='../hefty.php?cat=' + val;}</script> <?php$con = mysql_connect("phpmyadmin5.wadns.net:3307","hane","scorpion");if (!$con)  {  die('Could not connect: ' . mysql_error());  }		mysql_select_db("hefty", $con);		$quer2=mysql_query("SELECT DISTINCT c_category_name,c_category_id FROM c_category order by c_category_name");	$cat=$_GET['cat'];   if(isset($cat) and strlen($cat) > 0){  $quer=mysql_query("SELECT DISTINCT c_subcategory_name,c_subcategory_id FROM c_subcategory where c_category_id=$cat order by c_subcategory_name");  }	else{$quer=mysql_query("SELECT DISTINCT c_subcategory_name, c_subcategory_id FROM c_subcategory order by c_subcategory_name"); 	}		echo "<form method=post name=f1 action='classified_show.php'>";  echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select Category</option>";  while($noticia2 = mysql_fetch_array($quer2)) {  if($noticia2['c_category_id']==@$cat){	echo "<option selected value='$noticia2[c_category_id]'>$noticia2[c_category_name]</option>"."<BR>";}  else{echo "<option value='$noticia2[c_category_id]'>$noticia2[c_category_name]</option>";}  }  echo "</select>";  echo "<br /><br />";  echo "<select name='subcat'><option value=''>Select Subcategory</option>";	echo "<option value='1'>All</option>";  while($noticia = mysql_fetch_array($quer)) {  echo "<option value='$noticia[c_subcategory_id]'>$noticia[c_subcategory_name]</option>";  }  echo "</select>";  echo "<br /><br />";		$query="SELECT area_name,area_id FROM area order by area_name";   $result = mysql_query ($query);	  echo "<select name='area' > <option value=''>Select Area</option>";  while($nt=mysql_fetch_array($result)){  echo "<option value=$nt[area_id]>$nt[area_name]</option>";  }  echo "</select>"; 	echo "<br /><br />";  echo "<input type=submit value=Submit>";  echo "</form>";  	    mysql_close($con);?></div><div id="sel2" STYLE="visibility:hidden;"><!--table><tr><td align="left"><select name="directory" style="WIDTH: 125px"><option value="" selected=""></option><OPTION value="dude">dude</option><OPTION value="dude1">dude1</option><OPTION value="dude2">dude2</option><OPTION value="dude3">dude3</option></select></td></tr></table></div--> <script language=JavaScript>function reload(form){var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='../hefty.php?cat=' + val;}</script><?php$con = mysql_connect("phpmyadmin5.wadns.net:3307","hane","scorpion");if (!$con)  {  die('Could not connect: ' . mysql_error());  }		mysql_select_db("hefty", $con);		$quer2=mysql_query("SELECT DISTINCT d_category_name,d_category_id FROM d_category order by d_category_name");	$cat=$_GET['cat'];   if(isset($cat) and strlen($cat) > 0){  $quer=mysql_query("SELECT DISTINCT d_subcategory_name,d_subcategory_id FROM d_subcategory where d_category_id=$cat order by d_subcategory_name");  }	else{$quer=mysql_query("SELECT DISTINCT d_subcategory_name,d_subcategory_id FROM d_subcategory order by d_subcategory_name"); 	}		echo "<form method=post name=f1 action='../directory_show.php'>";  echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";  while($noticia2 = mysql_fetch_array($quer2)) {  if($noticia2['d_category_id']==@$cat){echo "<option selected value='$noticia2[d_category_id]'>$noticia2[d_category_name]</option>"."<BR>";}  else{echo "<option value='$noticia2[d_category_id]'>$noticia2[d_category_name]</option>";}  }  echo "</select>";  echo "<br /><br />";  echo "<select name='subcat'><option value=''>Select one</option>"; 	echo "<option value='1'>All</option>";  while($noticia = mysql_fetch_array($quer)) {  echo "<option value='$noticia[d_subcategory_id]'>$noticia[d_subcategory_name]</option>";  }  echo "</select>";  echo "<br /><br />";	$query="SELECT area_name,area_id FROM area order by area_name";   $result = mysql_query ($query);	  echo "<select name='area' > <option value=''>Select one</option>";    while($nt=mysql_fetch_array($result)){  echo "<option value=$nt[area_id]>$nt[area_name]</option>";  }  echo "</select>"; 	echo "<br /><br />";  echo "<input type=submit value=Submit>";  echo "</form>";  	    mysql_close($con);?></div>

Link to comment
Share on other sites

Hi, well to get this to 100% you'll have to put your foot on the gas. There are two ways i can think of:1) put the first select inside a form so you can GET/POST its value, pre-select it on the reload and put a : window.onload = select; so the js is executed well .... on load, this way having the second select populated and visible.2) or do it all with AJAX, avoiding the need of any forms at all, no reload of the page; but the down part of this is it won't work with js disabled, also you'll have to basically build almost everything from zero.both cases need a lot of work, so it's up to you wich way to go.

Link to comment
Share on other sites

I just read your post but have been busy today trying to write a &_GET. Its not working 100% but I made some progress I just dont know how to keep the first values after my second reload. Here is my code. Thanks for all your help

<script language=JavaScript>function reload1(form){var val1=form.dat.options[form.dat.options.selectedIndex].value; self.location='menu_l.php?dat=' + val1;}function reload(form){var val1=form.dat.options[form.dat.options.selectedIndex].value; var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='menu_l.php?dat=' + val1 + '&cat=' + val;}</script> <?php$data=$_GET['dat']; echo "<form method=get name=f2 action=''>";echo "<select name='dat' onchange=\"reload1(this.form)\"><option value='0'>Select</option>";echo "<option value='1'>Classifieds</option>";echo "<option value='2'>Directory</option>";echo "</select>"; echo "<br /><br />";	if ($data == "1")	{	  $quer2=mysql_query("SELECT DISTINCT c_category_name,c_category_id FROM c_category order by c_category_name");  	  $cat=$_GET['cat']; 	if(isset($cat) and strlen($cat) > 0){	$quer=mysql_query("SELECT DISTINCT c_subcategory_name,c_subcategory_id FROM c_subcategory where c_category_id=$cat order by c_subcategory_name");	}	  else{$quer=mysql_query("SELECT DISTINCT c_subcategory_name, c_subcategory_id FROM c_subcategory order by c_subcategory_name"); 	  }	  	  echo "<form method=post name=f1 action='classified_show.php'>";	echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select Category</option>";	while($noticia2 = mysql_fetch_array($quer2)) {	if($noticia2['c_category_id']==@$cat){	  echo "<option selected value='$noticia2[c_category_id]'>$noticia2[c_category_name]</option>"."<BR>";}	else{echo "<option value='$noticia2[c_category_id]'>$noticia2[c_category_name]</option>";}	}	echo "</select>";	echo "<br /><br />";	echo "<select name='subcat'><option value=''>Select Subcategory</option>";	  echo "<option value='1'>All</option>";	while($noticia = mysql_fetch_array($quer)) {	echo "<option value='$noticia[c_subcategory_id]'>$noticia[c_subcategory_name]</option>";	}	echo "</select>";	echo "<br /><br />";	  	  $query="SELECT area_name,area_id FROM area order by area_name";   	$result = mysql_query ($query);	  	echo "<select name='area' > <option value=''>Select Area</option>";  	while($nt=mysql_fetch_array($result)){	echo "<option value=$nt[area_id]>$nt[area_name]</option>";	}	echo "</select>"; 	  echo "<br /><br />";	echo "<input type=submit value=Submit>";	echo "</form>";  }	else	{	  $quer2=mysql_query("SELECT DISTINCT d_category_name,d_category_id FROM d_category order by d_category_name");  	  $cat=$_GET['cat']; 	if(isset($cat) and strlen($cat) > 0){	$quer=mysql_query("SELECT DISTINCT d_subcategory_name,d_subcategory_id FROM d_subcategory where d_category_id=$cat order by d_subcategory_name");	}	  else{$quer=mysql_query("SELECT DISTINCT d_subcategory_name,d_subcategory_id FROM d_subcategory order by d_subcategory_name"); 	  }	  	  echo "<form method=post name=f1 action='../directory_show.php'>";	echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";	while($noticia2 = mysql_fetch_array($quer2)) {	if($noticia2['d_category_id']==@$cat){echo "<option selected value='$noticia2[d_category_id]'>$noticia2[d_category_name]</option>"."<BR>";}	else{echo "<option value='$noticia2[d_category_id]'>$noticia2[d_category_name]</option>";}	}	echo "</select>";	echo "<br /><br />";	echo "<select name='subcat'><option value=''>Select one</option>";   	echo "<option value='1'>All</option>";	while($noticia = mysql_fetch_array($quer)) {	echo "<option value='$noticia[d_subcategory_id]'>$noticia[d_subcategory_name]</option>";	}	echo "</select>";	echo "<br /><br />";	  $query="SELECT area_name,area_id FROM area order by area_name";   	$result = mysql_query ($query);	  	echo "<select name='area' > <option value=''>Select one</option>";		while($nt=mysql_fetch_array($result)){	echo "<option value=$nt[area_id]>$nt[area_name]</option>";	}	echo "</select>"; 	  echo "<br /><br />";	echo "<input type=submit value=Submit>";	echo "</form>";  }		  mysql_close($con);?>

Link to comment
Share on other sites

Just tested my code and it works, yes there still is some kinks to sort but ultimately if i select directory the directory menu appear and if i select classifieds the classifieds menu appear. Would still like the first option to stay in the url and not change to 0. If you can please go over my code and point out some problems it would really be appreciated. I'm so excited about my code that works

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...