954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Refresh + Combo Box

Pretty simple, just dont know how to find the solution XS.

I have a combo box, that once u select the required attribute (A, B, C).

It should display the apporiate text of A, B, C below it.

So any ideas?

Thanks, Regards X

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

you can using this:
$_POST['dropdown list name'];
if this not true please give me more explains.

almualim
Light Poster
28 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

I said it in the other thread, have an onchange event to submit the page when you select a value from the dropdown list. When the page is submitted, you can know which option was selected from the dropdown list. ($val = $_POST['dropdownlistname']; ) Then query the table with this value as condition and retrieve the data.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Hi nav33n, my php GURU!

<?php	$con = mysql_connect("localhost","root");	mysql_select_db("test");	$query = "select col1 from table";	$result = mysql_query($query);	echo "<form method='post' action='test.php'>";	echo "<select name=dropdown1 onchange='javascript: document.form.submit();'>";	while($row = mysql_fetch_array($result)) {		$value = $row['col1'];		echo "<option value='".$value."'>$value</option>";	}	echo "</select>"; 	$firstdropdownlistvalue = $_POST['dropdown1'];	$query2 = "select * from table where col2 = '$firstdropdownlistvalue'";	$result2 = mysql_query($query2);	echo "<select name=dropdown2>";	while($row2 = mysql_fetch_array($result2)) {		$value2 = $row2['col1'];		echo "<option value='".$value2."'>$value2</option>";	}	echo "</select>";	echo "</form>";?><?php
	$con = mysql_connect("localhost","root");
	mysql_select_db("test");
	$query = "select col1 from table";
	$result = mysql_query($query);
	echo "<form method='post' action='test.php'>";
	echo "<select name=dropdown1 onchange='javascript<b></b>: document.form.submit();'>";
	while($row = mysql_fetch_array($result)) {
		$value = $row['col1'];
		echo "<option value='".$value."'>$value</option>";
	}
	echo "</select>";
	
	$firstdropdownlistvalue = $_POST['dropdown1'];
	$query2 = "select * from table where col2 = '$firstdropdownlistvalue'";
	$result2 = mysql_query($query2);
	echo "<select name=dropdown2>";
	while($row2 = mysql_fetch_array($result2)) {
		$value2 = $row2['col1'];
		echo "<option value='".$value2."'>$value2</option>";
	}
	echo "</select>";
	echo "</form>";
?>


From your other thread a few questions, as mine is linked to a mysql database which the values are retrieved from that.

I have pretty much everything you have there already minus the on change even like you said.

echo "<select name=dropdown1 onchange='javascript: document.form.submit();'>";


So this is the only code I need to add to let my form submit itself and show the appropriate data?

Also another quick Q, once I have selected the drop down item and refreshed the page, I wish to keep the selected item in the combo box and not be reset to the intial value.Any ideas?

Thanks for all your help again, ill try that now. - I just tested it and it works BUT my first drop down isnt refreshing but my second is =S (Ill go debug and keep you posted)

Regards, X

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

After a whole bunch of debugging everything is done!
Thanks nav once again your a legend ;)

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

:) lol.. no ! I am a learner.. I am glad your problem was fixed !

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You