Jump to content


Photo

Drop Down Menu


  • Please log in to reply
2 replies to this topic

#1 jamesnkk

jamesnkk
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 March 2006 - 03:14 AM

Hi,

I have an entry form that contain some text entry and one drop down menu which I retrieve the data from a table.
The problem is when I click the submit button, It go to the 2nd form to validate for error, if error it will return to the entry form, I could manage to retain all text entry, so that user donlt have to re-type all over again.

But I cannot retain the selected item from a drop down menu, is there a way ?, please help me.

Thanks

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 27 March 2006 - 03:25 AM

what method are you using to re-populate the text field? if your are just echoing the posted values (value="<? echo $_POST['value'] ?>") then for the drop down just do:


<select name="dropdown">
<option value="option1" <? if($_POST['dropdown'] == 'option1'){ echo "selected"; } ?>> Option 1 </option>
<option value="option2" <? if($_POST['dropdown'] == 'option2'){ echo "selected"; } ?>> Option 2 </option>
<option value="option3" <? if($_POST['dropdown'] == 'option3'){ echo "selected"; } ?>> Option 3 </option>
</select>

get the idea?
"Confidence in the face of risk."

#3 jamesnkk

jamesnkk
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 March 2006 - 03:55 AM

[!--quoteo(post=358756:date=Mar 27 2006, 11:25 AM:name=micah1701)--][div class=\'quotetop\']QUOTE(micah1701 @ Mar 27 2006, 11:25 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
what method are you using to re-populate the text field? if your are just echoing the posted values (value="<? echo $_POST['value'] ?>") then for the drop down just do:
<select name="dropdown">
<option value="option1" <? if($_POST['dropdown'] == 'option1'){ echo "selected"; } ?>> Option 1 </option>
<option value="option2" <? if($_POST['dropdown'] == 'option2'){ echo "selected"; } ?>> Option 2 </option>
<option value="option3" <? if($_POST['dropdown'] == 'option3'){ echo "selected"; } ?>> Option 3 </option>
</select>

get the idea?
[/quote]
Thanks for the prompt reply, here the code to populate from a table on form-1(create_partno.php)
<select name="aid" id="aid" size="1">
<option selected value="">Please select</option>
<?
while ($company = mysql_fetch_array($companys) ) {
$aid=$company['company'];
$aname=htmlspecialchars($company['company']);
echo "<option value='$aid'>$aname</option>\n";
}
?>
</select>

Then on the 2nd form (create_part.php) I use header to return, -
header("Location: create_partno.php?part_no=".$_POST['part_no']."&supp_partno=".$_POST['supp_partno']."&part_desp=".$_POST['part_desp']
."&cost_price=".$_POST['cost_price']."&sell_price=".$_POST['sell_price']
."&brand=".$_POST['brand']."&package=".$_POST['package']."&qty_bal=".$_POST['qty_bal']
."$aid=".$_POST[aid] ."&qty_order=".$_POST['qty_order']."&re_order=".$_POST['re_order']."&error=".$_POST['error'].$error1 );


When return to form-1, Just could not retain the selected value from the drop down menu,





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users