help me to set value in drop down .I want to fetch two ids 1.$row[0].
2.$row[3] from a view and selected is not set.

<td colspan='2'><b>Select a Publication and Year</b><br>
	
		<select name="publication_name" id="publication_name" onchange="show_year(this.value);">		
		<?php
			$get_publn_name=mysql_query("SELECT anPublicationId,sPublicationName,sPublicationShortName,anYearId,nPublicationYear FROM view_publication_year order by nPublicationYear");
		?>
			<option value=0>-- Select Publication --</option>
		<?php
			while($row=mysql_fetch_row($get_publn_name))
			{
				if(isset($_GET["id"]) and $_GET["id"]==$row[0])
				{
					echo "<option value=".$row[0].",".$row[3]." selected=true>".$row[1]."-".$row[4]."</option>";
				}
				else
					echo "<option value=".$row[0].",".$row[3].">".$row[1]."-".$row[4]."</option>";
			}
		?>
		</select> 
	</td>

Recommended Answers

All 2 Replies

help me to set value in drop down .I want to fetch two ids 1.$row[0].
2.$row[3] from a view and selected is not set.

<td colspan='2'><b>Select a Publication and Year</b><br>
	
		<select name="publication_name" id="publication_name" onchange="show_year(this.value);">		
		<?php
			$get_publn_name=mysql_query("SELECT anPublicationId,sPublicationName,sPublicationShortName,anYearId,nPublicationYear FROM view_publication_year order by nPublicationYear");
		?>
			<option value=0>-- Select Publication --</option>
		<?php
			while($row=mysql_fetch_row($get_publn_name))
			{
				if(isset($_GET["id"]) and $_GET["id"]==$row[0])
				{
					echo "<option value=".$row[0].",".$row[3]." selected=true>".$row[1]."-".$row[4]."</option>";
				}
				else
					echo "<option value=".$row[0].",".$row[3].">".$row[1]."-".$row[4]."</option>";
			}
		?>
		</select> 
	</td>

I don't think selected=true actually works in all browsers, I think what you want is selected="selected". Also I don't know what will happen with your values since you are including two fields in each separated by commas if you don't include some type of quotation in there. For example if I have <option value=tow,three> who knows what is going to happen when you test across different browsers and platforms.. You really should include these values in quotations as well as selected="selected". quotations may seem minute until you have to look through a large html document and try to determine if your html is being parsed correctly. This is another thing that you can do is view source from a browser and paste it into an html editor and see if it parses correctly.

Using just "selected" will do the job.
<option value='2' selected>Sachin</option>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.