Page 1 of 1

[SOLVED] How to get an option selected?

Posted: Mon Sep 27, 2004 10:18 am
by ljCharlie
Below is a drop down list I have in my form.

Code: Select all

<form name="frmScholarship" method="post" action="<?php $HTTP_SERVER_VARS['PHP_SELF']?>">
			<select name="sltScholarship" id="sltScholarship" onChange="frmScholarship.submit()">
			  <?php
do {  
?>
			  <option value="<?php echo $row_rsScholarshipType['sectionID']?>"<?php if (!(strcmp($row_rsScholarshipType['sectionID'], 100))) {echo "SELECTED";} ?>><?php echo $row_rsScholarshipType['category']?></option>
			  <?php
} while ($row_rsScholarshipType = mysql_fetch_assoc($rsScholarshipType));
  $rows = mysql_num_rows($rsScholarshipType);
  if($rows > 0) {
      mysql_data_seek($rsScholarshipType, 0);
	  $row_rsScholarshipType = mysql_fetch_assoc($rsScholarshipType);
  }
?>
			  </select>
			  </form>
The problem I have is that when a user select an option from the drop down list and the page refresh, the drop down option list that the user chose did not get selected after the page is refresh. How do I get the option selected to be selected and shown on the drop down list after the page refresh?

ljCharlie

Posted: Mon Sep 27, 2004 10:22 am
by Joe
An easy way around this would be to "POST" the users choice and setup a simple if statement to determine which option is to be "SELECTED".

Posted: Mon Sep 27, 2004 10:41 am
by feyd
Charlie, you've been here long enough to know that you were supposed to use

Code: Select all

tags.. 

look through the results of this search [devnet]+form +selected[/devnet] for lots of threads about creating selection lists.

Posted: Mon Sep 27, 2004 1:08 pm
by ljCharlie
Well, at first I was going to put into PHP but then I also have some code that are not PHP so that is why I didn't put in PHP. Sorry.

Anyway, I got it. It is working now.

Many thanks for your help!

ljCharlie