onChange Select did not display?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

onChange Select did not display?

Post by jayson.ph »

Hi all,

please help -> what should the possible wrong in this part: since when i select the the list and it work okay. but after load the form the selected name is did not display and it return in default "Select Supplier".

Code: Select all

echo "<select name= 'product' onchange = 'reload(this.form)'> <option value = ''>Select Supplier..</option>";
			
					while($row_select_p = mysql_fetch_array($SQL_QUERY_PRODUCT_)) 
				{ 
						if($row_select_p['supplier_id']== @$product)
				{
				echo "<option value = '$row_select_p[supplier_id]'>$row_select_p[supplier_name]</option>";
					
				}
			else{echo  "<option value = '$row_select_p[supplier_id]'>$row_select_p[supplier_name]</option>";}

				}
			echo "</select>";
and also i already get the value if the id=> Image
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: onChange Select did not display?

Post by social_experiment »

My understanding of what you want to achieve with the script: Have the selected item from the menu be the item that is selected when the page reloads. So if you select "Page", on the reload "Page" will be the item selected and not "Select supplier..."

Is this correct on my part?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: onChange Select did not display?

Post by Mordred »

You need to output a selected="selected" attribute in the <option> tag for the entry that is currently selected (first <option..> in your code)
Post Reply