0

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>";
}
3
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by nav33n
0

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.

0

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>
0

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>";
}
0

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

0
$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 ""; }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.