Jump to content

hide Drop down list if no need


garevn

Recommended Posts

Hello i am really new in programming and i cant figure out how to solve the following problem.i am having a drop down list for the user helping him reduce results.My list looks like this

<select name="products2" id="soch" onchange="showUser()">           <option value="" selected="selected">Sochet</option>           <?phpdo {  ?>           <option value="<?php echo $row_sochet['sochet']?>"><?php echo $row_sochet['sochet']?></option>           <?php} while ($row_sochet = mysql_fetch_assoc($sochet));  $rows = mysql_num_rows($sochet);  if($rows > 0) {      mysql_data_seek($sochet, 0);	  $row_sochet = mysql_fetch_assoc($sochet);  }?>         </select>

for example when the user choose the processors category then possible sochets display.I want to hide this drop down if he choose another category ex. printers which dont contain any sochet

Link to comment
Share on other sites

You need to use js to change the DOM of the page. You can bound a js function to onchange event which will look for the selected element if its other than sochet then you can remove the <select> node or you can make it hideIf other category also pull data from database to show the dropdown list and you want to change that dropdown dynamicaly then i think you need to look for ajax also. and then you can replace the <select> node with reposne data of ajax.

Link to comment
Share on other sites

Hello again man.my current ajax js looks like this atm

<script type="text/javascript">	function showUser(){var q=document.getElementById("manuf");var q_val = q.options[q.selectedIndex].value; var t=document.getElementById("soch");var t_val = t.options[t.selectedIndex].value;var c=document.getElementById("order");var c_val = c.options[c.selectedIndex].value;if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari	xmlhttp=new XMLHttpRequest();}	else	{// code for IE6, IE5	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}	xmlhttp.onreadystatechange=function(){var q=document.getElementById("manuf");var q_val = q.options[q.selectedIndex].value; var t=document.getElementById("soch");var t_val = t.options[t.selectedIndex].value;var c=document.getElementById("order");var c_val = c.options[c.selectedIndex].value;	if (xmlhttp.readyState==4 && xmlhttp.status==200){	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}} xmlhttp.open("GET","productsdata.php?q=" + q_val + "&t=" + t_val+"&c=" +c_val, true); xmlhttp.send();} </script>

Could i modifie it or i should add a new jsIf u could provide some example rows would be great.

Link to comment
Share on other sites

Hello, Its looks good and little bit of modification in it should make it work as you want.can you tell now are you getting the correct and expected data from responseText?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...