The following code may be 'OTT' but it's future proof IMO:
Code:
<?php
// Set Choice variable
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : 'none';
// Check value of param against $thisValue
function checkSelected($thisValue) {
if($choice == $thisValue) {
return 'selected="selected"';
}
}
// Our drop down options
$options = array(
'none' => 'None',
'option1' => 'option1',
'option2' => 'option2',
'option3' => 'option3'
);
// Loop through each option assigning the html to $return
foreach($options as $key=>$value) {
$return .= '<option value="'.$key.'" '.checkSelected($key).'>'.$value.'</option>';
}
?>
<select id="select1" name="select1" class="dropper" value="<?=$select1;?>">
<?php
// We could just loop here but I prefer to output the $return variable
echo($return);
?>
</select>
In order to add more options, you just need to add more values to the $options array.
I removed the name & id on each option as I couldn't see the point in them being there.
In order for the above code to work, you need to capture the value from the select1 on your error page then pass it back via GET or POST as 'choice', the script will take care of the rest.
I hope this helps, if not, let me know the issues.
only one thing with your code Uze - <select> elements don't take a value attribute... other than that - pretty close to what I'd do...
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak
The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Horus_Kol disagrees: stating the obvious doesn't help things
But AFAIK when it's the only thing to do to to ensure crossbrowser combability i think it's in place to mention.
After page refresh you need to change the selected="selected" by yourself as some browsers will remember the selected value and some will not.
But AFAIK when it's the only thing to do to to ensure crossbrowser combability i think it's in place to mention.
After page refresh you need to change the selected="selected" by yourself as some browsers will remember the selected value and some will not.
He was obviously missing this.
maybe - but without showing a PHP code snippet for how to determine which of the options should be selected, your statement is next to useless...
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak
The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
So exact statement what needs to be done is useless and only amount of lines i wrote or code i produce matters?
no - but when that exact statement isn't supported by any suggestions on how to do the thing that you say should be done, then that is useless.
now, please, drop this off-topic conversation...
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak
The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Select don't have a value or selected property. Those are option propertys.
Name property belogns to select, not option.
And as peg stated no same ID:s
This should make it work, im done with this thread.