PDA

View Full Version : How do I make a Variable Lenght Combobox/Dropdown menu?


AsscBB
07-23-2008, 03:37 AM
I'm trying to build a user input form which takes the userid and runs a query. The results from the query are then put in a dropdown menu for the user to make a selection. Visually, I have this working just right, but the problem is the data is not being captured. I'm trying to tweak the Form Hack by Abe1 https://vborg.vbsupport.ru/showthread.php?t=126676 so that the dropdown isn't a static length.

I'm working with 2 templates and php code. The first template has the general page layout, and the second template has the section of code which is looped. The section of the main form template which drives the dropdown is:

<tr>
<td class="alt1" valign="middle">
<b>$dropdownquestion1</b>:
</td>
<td class="alt1" valign="middle" colspan="2">
<select name="dropdownanswer1">

$dropdownresult

</select></td>
</tr>

The template file which was created to drive the dropdown options is:


combobox_options:
<option value="$dropdownchoice[$key]" <if condition="$dropdownchoice[$key] == $dropdownanswer1">selected="selected"</if>>$dropdownchoice[$key]</option>



$dropdownresult is built in the php file using:

$get_myvars=$db->query_read("
SELECT myvar
FROM " . TABLE_PREFIX . "my_table
WHERE
userid = $this_user
");

$option_number = 1;
while ($get_myvar=$db->fetch_array($get_myvars))
{
$dropdownchoice[$option_number] = $get_myvar[myvar];
$option_number++;
}

foreach ($dropdownchoice as $key => $value)
{
eval('$dropdownresult .= "' . fetch_template('combobox_options') . '";');
}




Now my problem is being able to capture the result from the dropdown menu. As I said, it displays the results of the query as desired, and the user can manipulate the menu to select a value, but the form does not capture that into a variable for use. Can anyone help???


Thanks!

Dismounted
07-23-2008, 09:56 AM
You should just be using:
$value
Instead of:
$dropdownchoice[$key]

AsscBB
07-25-2008, 07:24 AM
Works like a champ!

cheers!