Hi,
I am doing my first project for school, and I am having a small problem with the code. I found a lot of solutions on Google but they are all confusing me, as this is my first PHP program I really don’t understand them.
I have a simple form, that has a few combo boxes. I am supposed to make the form sticky, and it works just fine except on my combo box control.
.. function starts ..
# temporary storage for current settings
$current_month = "";
$current_day = "";
$current_year = "";
# select option
$sel = "";
# if the form has been submitted, record the current settings so they can be
# posted back to the form making it sticky.
if (isset($_POST['submitted'])) {
# recording current user settings
$current_month = $_POST['month'];
$current_day = $_POST['day'];
$current_year = $_POST['year'];
}
.. generate the select box ...
# make the months pull-down-menu
echo '<select name="month">';
foreach ($months as $key => $value) {
# if the current month the user has selected is the same month as the
# one in $value on this iteration, mark this option as the selected option.
if ($current_month == $value) {
$sel = 'selected="selected"';
}
else {
# this option is not selected
$sel = 'selected=""';
}
# create the option, and mark it as selected if needed.
echo "<option value=\\"$key\\" $sel>$value</option>\
";
}
echo '</select>';
I don’t think you will need the rest of my program. I am basically trying to see if the value (being generated) is the value in the $_POST variable. If it is then that was the value that needs to be sticky so I mark that as selected.
But when I do this December is always selected and all of the code when I view source in the browser has all of the Selected properties as an ampty string.
I’m not even sure if this fires, or if the combo box is regenerated every time the post back is called.
It appears that this line always fires
else {
# this option is not selected
$sel = 'selected=""';
}
I’m not sure how to debug it yet, we didnt get that far.