I have a php generated page that contains 63 drop-down menus (with names v1, v2, v3, etc).
I was wondering if I go to the page and select 10 of the 63 dropdowns, can I save those selections so the next time I visit the page the drop-down menus will already be on the respective choices? I'm not sure if this can be done in PHP, or javascript.
Here's more or less what I'd do (or have done) with PHP in such situations. If you are using cookie to store the selections, I'm sure you can do it with JavaScript, too:
PHP Code:
<?php
// Generate an array to hold your combobox value/options.
// This is for this particular script only - I guess you have this kind of array already anyway.
for ($i = 1; $i <= 63; $i++) {
$a_options['v'.$i] = 'Option '.$i;
}
// Pre-selected options' values without 'v' - this way, you can save one char-space per entry.
// Again, this is for this demo only. You should get this array from cookie (that you have set before) or database or any kind of storage you want to use.
// What I'd do perhaps is to setcookie() previous selections, serialized with implode(',', substr($_REQUEST['mySelect']), 1) or something and explode() it when pre-selecting the options.
$a_selected = array(5, 6, 10, 20, 35, 38);
// Show the combobox, options pre-selected in accordance with $a_selected.
echo '<select name="mySelect[]" multiple="multiple" size="10">';
foreach ($a_options as $key => $val) {
// It's important that $a_selected be an array or you'll get an error on in_array().
// substr() is not necessary if we choose to store the selections as they are (i.e. with "v" prefix)
echo '<option value="'.$key.'"'.(in_array(substr($key, 1), $a_selected) ? ' selected="selected"' : '').'>'.$val.'</option>'."\n";
}
echo '</select>';
?>
You can literally copy-and-paste the above to see the effect, but please read the comments, too. Good luck.
EDIT: Forgot the preceeding white space before selected="selected".