1
phillipd
Strugglnig to read the selected string from a dropdown
  • 2004/7/16 6:57

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I have a dropdown "select" in a form that was filled in from a DB. I'm trying to read the selected value. I can't seem to figure this out. Can someone please assist me?

Loading the dropdown works fine:

$results = $xoopsDB->query("SELECT `types_title` FROM ". XOOPS_DB_PREFIX ."_dar_types");
$select_str = "";
while ($opt = $xoopsDB->fetchArray($results)) {
$sel = $opt['types_title'];
$select_str .= "<OPTION VALUE=> $sel</OPTION>\n";
}

echo "<form action='index.php' method='post'>
<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td class='bg2'>
<table width='100%' border='0' cellpadding='4' cellspacing='1'>";

// "select_str" are the "option values" for the select gadget
echo "
<tr><td nowrap='nowrap' class='bg3'>"._XD_SELTITLE." </td><td class='bg1'><SELECT name='selection[]' size='1'> $select_str</SELECT>
<input type='submit' name='editcontents' value='"._SUBMIT."' />
<input type='hidden' name='op' value='listcontents' />
<input type='hidden' name='stage' value='2' />
<input type='hidden' name='cat_id' value='".$cat_id."' /></td>";

Notice I set the stage to 2 and when the submit button is pressed it reruns the same code which tries to extract the value of the dropdown but I can't seem to get the syntax correct...

if($stage == 2) {
$res = $_POST['selection']; <=== won't read the selection...
echo $_POST['selection'];
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_TITLE." </td>
<td class='bg1'><input type='text' name='contents_title' value='$selection' size='52' maxlength='255' /></td></tr>";
}
else {
echo "<tr><td nowrap='nowrap' class='bg3'>"._XD_TITLE." </td>
<td class='bg1'><input type='text' name='contents_title' value='$selection' size='52' maxlength='255' /></td></tr>";
}

Any help is greatly appreciated...

Thanks

Doug P

2
Mithrandir
Re: Strugglnig to read the selected string from a dropdown

if you just want a single value sent, you should not give the SELECT a name ending with [] as this indicates an array value to the output

3
phillipd
Re: Strugglnig to read the selected string from a dropdown
  • 2004/7/16 14:21

  • phillipd

  • Quite a regular

  • Posts: 219

  • Since: 2004/4/20


I think I've tried that, to no avail. Do you have a sample snippit of reading an item from a dropdown that you know works? Thank you for your valuable time sir!

[Edit]

Figured it out... I didn't realize I needed the text in two places in the option value statement.

I was doing:

$select_str .= "<OPTION VALUE=>$sel</OPTION>\n";

Needed...

$select_str .= "<OPTION VALUE='$sel'>$sel</OPTION>\n";


Regards

Doug P

4
Mithrandir
Re: Strugglnig to read the selected string from a dropdown

Bleh... I should have caught that one.

Who's Online

161 user(s) are online (132 user(s) are browsing Support Forums)


Members: 0


Guests: 161


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits