hi
now i want the first one alone to be seclectes on page load,rest should word based on the user clicks

SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
function view(s)
{
if(ss.options[s.selectedIndex].value!="none")
{
var a=document.getElementById('IndustryType');
var temp=a.value;
parent.frameright.location = "http://www.website.com/web_desc.php?var=" + temp;
}
}
-->
</script>

$result=mysql_query("select * from jopposting where owns='$id' and chkshare='yes' order by jtitle asc");
if($result)
{
print "<select name='IndustryType' language='javascript' onChange='view(this);' size='12' style='width: 300px'>";
while($myrow = mysql_fetch_array($result))
{
print "<option value='$myrow[0]'>$myrow[1]</option>";
}

Try giving your select element focus using onLoad in your BODY tag. That should automatically select the first option in the list. <BODY onLoad="mySelect.focus();"> You will need to give the select an ID.

Alternatively you could add 'SELECTED' to your option tag when you populate the first option from your database.

If you use onload function, it will replace whatever you selected by the default value. What you can do is, check if the user has already selected any value from the listbox. If the user has selected a value already, then make that as "selected", else, make the default as selected.
Eg.

<?php
$selectedvalue = isset($_POST['selectbox']) ? $_POST['selectbox']:"default_select";
?>
<form method="post" action="select.php">
<select name='selectbox'>
<option value='default_value' <?php if($selectedvalue=="default_value") { echo "selected"; } ?>>default</option>
<option value='1' <?php if($selectedvalue=="1") { echo "selected"; } ?>>1</option>
<option value='2' <?php if($selectedvalue=="2") { echo "selected"; } ?>>2</option>
</select>
<input type="submit" name="submit" value="submit">
</form>

i have a while loop,then please do tell me how to set the default value for the list box

print "<select name='IndustryType' language='javascript' onChange='view(this);' >";
while($myrow = mysql_fetch_array($result))
{
print "<option value='$myrow[0]'>$myrow[1]</option>";
}

In the while loop, If $_POST == $myrow[0], make that as selected, else make a default value "selected".

sorry i did not get you,how to set default value

$selectedvalue = isset($_POST['selectbox']) ? $_POST['selectbox']:"default_select";

Then do the check as same as I have said above.

If ($selectedvalue == $row[0]) { echo "selected"; } else { echo ""; }
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.