Click to See Complete Forum and Search --> : list menu
kproc
11-07-2006, 01:34 PM
Hi
I want to set a list menu so that when the user selects a value it reloads the page page on the value set with the list menu
example code
<form name="setmonth" method="post" action="">
<label>
<select style="width:55px" name="S_month" id="S_month">
<option value="<? echo date("m"); ?>"></option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
kproc
11-07-2006, 01:44 PM
I need it to somehow get the select option value so that I can use it in the same page
so_is_this
11-07-2006, 01:52 PM
Do you mean *after* submit? ...or, *before* submit?
After would be a PHP answer. Before would be a JavaScript answer.
bokeh
11-07-2006, 02:06 PM
I take your question to mean: Select the current month automatically and make the form sticky so if the selection is changed that change will not be lost on the reload.<form name="setmonth" method="post" action="">
<label>Month:</label>
<select name="S_month" id="S_month">
<?php
$months = array('01'=>'January', '02'=>'Febuary', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
$month = (isset($_POST['S_month']) and is_numeric($_POST['S_month'])) ? $_POST['S_month'] : date('m') ;
foreach($months as $number => $word)
{
echo ' <option value="'.$number.'"'.(($number == $month)?' selected="selected"':'').'>'.$word.'</option>'."\n";
}
?> </select>
<input type="submit" value="submit">
</form>
kproc
11-07-2006, 02:27 PM
thank you for the help
Below is code that works and does what its suppose to, but It sets the month back to the the current month as its suppost to. I want to change it so that If I pick June then when I click the go button then the munth name would stay and not change back to the current month
<table class="columntable">
<form name="setmonth" method="post" action="<?php echo $PHP_SELF; ?>">
<tr>
<th class="tableheader" colspan="5">Buddy Events for
<label>
<select style="width:100px" name="event_month" id="event_month">
<option value="<? echo date("m"); ?>"><? echo date("F"); ?></option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<input type="submit" name="submit" value="Go">
</form>
<tr>
<td class="rowLeft">Event Date</td>
<td class="rowRight">Description</td>
<td class="rowRight">Category</td>
<td class="rowRight">Details</td>
<td class="rowRight">Event Owner</td>
</tr>
<?PHP
while ($buddy_find = mysql_fetch_array($buddy_result)){
$event_description = $buddy_find['event_description'];
$event_date = $buddy_find['event_date'];
$event_category = $buddy_find['event_category'];
$event_details = $buddy_find['event_details'];
$event_id = $buddy_find['event_id'];
$event_owner = $buddy_find['userid'];
$submit = $_POST['submit'];
$set_month = $_POST['event_month'];
if($submit) {
$current_month = $set_month;
}else{
$current_month = date(m);
}
$date_array = explode("-",$event_date);
$events_for_month = $date_array[1];
if($events_for_month == $current_month){
bokeh
11-07-2006, 02:31 PM
That is exactly what the code I posted does... And without the duplicated option.
kproc
11-07-2006, 03:01 PM
I got it working, there was an issue with variable name.
thank you
bokeh
11-07-2006, 03:15 PM
there was an issue with variable name.Yeah, I saw you changed it between your two posts.
kproc
11-08-2006, 04:22 PM
I want to do something simpilar of anther form but can figure it out. I'll explain...
I want to create a list/menu that shows the months of the year with the corisponding numeric value assigned as the the value.
there is a variable that is set to equal the numeric month value. When the variable is set I want the list/menu to dispaly the text month value. So the page is setting the variable value (from mysql table). This is different then the code in this post in that the user sets the value in the above code
any help is excellent
bokeh
11-08-2006, 04:40 PM
I want to create a list/menu that shows the months of the year with the corisponding numeric value assigned as the the value.
there is a variable that is set to equal the numeric month value. When the variable is set I want the list/menu to dispaly the text month value. So the page is setting the variable value (from mysql table).Why didn't you explain this in the first place? Just substitute the $_POST variable with your DB variable.
kproc
11-08-2006, 04:59 PM
Thanks once again. I have two page that does the things that I explained.
thank you