PDA

View Full Version : set current value($var) for dropdown


BobNZ
06-29-2004, 08:18 PM
I have a dropdown box on an update page
from wich the user selects a record for
update.

When the user clicks 'select' the textboxes
on the page are populated. I want to
change the text boxes to drop
down so the user can select new value
from drop down and click 'update' to set
new value.

But I want the dropdowns to be populated
with the current value when the 'select'
button is clicked.
What I need to know is how to show the
current value in the drop down boxes
initially.

Hope this is clear enough.

B

panreach
06-29-2004, 10:31 PM
here's one example.


function build_secret_question($preselectedid, $name, $tabindex, $class="sl") { //default $class="sl" if not said
$questions = array(
"1"=>"What is number one?",
"2"=>"What is number two?",
"3"=>"What is number three?",
"4"=>"What is number four?",
"5"=>"What is number five?",
"6"=>"What is number six?"
);

$output .= "<select name='".$name."' id='".$name."' tabindex='".$tabindex."' class='".$class."'>";

while (list ($id, $question) = each ($questions)) {
if ($id == $preselectedid) {
$selected = " SELECTED";
}
else {
$selected = "";
}

$output .= "\n<option value='" . ov($id) . "'$selected>" . ov($question)."</OPTION>";
}

$output .= "\n</select>";
return $output;
}

// call it like
echo build_secret_question("1", "my_select_box", "0", "sl");

BobNZ
06-30-2004, 03:01 AM
Thanks but I figured this out,

$Mrow[3] is the index of the row returned from the monitor query that holds the monitor make. Monitor query populates the monitor text/now combo boxes of the update page
$MROWquery= "select * from \"tblMonitor\" where \"WSID\" = '".$_POST['WSID']."'";
$result = pg_query($dbh,$MROWquery);
$Mrow=pg_fetch_row($result);

<select style='width:110px' name="MMake" >
<?php
db_connect();
$makequery= "SELECT distinct \"MMake\" from \"lkpMonitor\"where \"MMake\" is not null ";
$result = pg_query($dbh ,$makequery);
while ($row = pg_fetch_array($result))
{
if($row[0]==$Mrow[3])
{
echo"<option selected=\"selected\">".$row[0]."</option>";
}
print ("<option> $row[0]</option>");
}
?>
</select>