Jump to content

Drop down state


frist44

Recommended Posts

best method of reproducing select values

 

 

 

<?php

$select = array("Option1","Option2","Option3","Option4","Option5);

echo "<select name='test'>";
foreach($select as $key=>$value){
echo "<option value='".$key."' ";
if($_POST['select'] == $key){
echo 'selected = 'selected' ";
}
echo >".$value."</option>";
}
echo "</select>";
?>

super easy and easy to reproduce

Link to comment
https://forums.phpfreaks.com/topic/148115-drop-down-state/#findComment-777495
Share on other sites

best method of reproducing select values

 

 

 

<?php

$select = array("Option1","Option2","Option3","Option4","Option5);

echo "<select name='test'>";
foreach($select as $key=>$value){
echo "<option value='".$key."' ";
if($_POST['select'] == $key){
echo 'selected = 'selected' ";
}
echo >".$value."</option>";
}
echo "</select>";
?>

super easy and easy to reproduce

 

I have this and it works when I postback, but not on initial load:

 

		<select name="ddsite">

<?php

$select = array('asasungard' => 'Sungard', 'asaexton' => 'Exton');

foreach($select as $key=>$value){
echo '<option value="'.$key.'"';

if($_POST['ddsite'] == $key){
	echo 'selected="selected" ';
}

echo ">".$value."</option>";
}

?>

	</select>

 

Do I need something to see if that post value is set?

Link to comment
https://forums.phpfreaks.com/topic/148115-drop-down-state/#findComment-777544
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.