php function, dropdown & radio button issue
Posted: Tue Feb 24, 2009 4:07 pm
hi,
i am newbie with php....with below code i am trying to create dropdown list populated by radio button.
1. if month radio button is clicked the dropdown will be populated with months - not working
2. if week radio button is clicked the dropdown will be populated with 4 weeks - not working
3. when i use other ways to populate dropdown, the values come in url but not on the page itself.
can someone please check and see what i am doing wrong...i really appreciate it.
thanks, let me know if anything else i am missing
i am newbie with php....with below code i am trying to create dropdown list populated by radio button.
1. if month radio button is clicked the dropdown will be populated with months - not working
2. if week radio button is clicked the dropdown will be populated with 4 weeks - not working
3. when i use other ways to populate dropdown, the values come in url but not on the page itself.
can someone please check and see what i am doing wrong...i really appreciate it.
Code: Select all
<?php
function createMonths($id='month_select', $selected=null)
{
$months = array(
1=>'January',
2=>'February',
3=>'March',
4=>'April',
5=>'May',
6=>'June',
7=>'July',
8=>'August',
9=>'September',
10=>'October',
11=>'November',
12=>'December');
$selected = is_null($selected) ? date('m') : $selected;
$select = '<select name="'.$id.'" id="'.$id.'">'."\n";
foreach($months as $key=>$mon)
{
$select .= "<option value=\"$key\"";
$select .= ($key==$selected) ? ' selected="selected"' : '';
$select .= ">$mon</option>\n";
}
$select .= '</select>';
return $select;
}
function createWeek($id='week_select', $selected=null)
{
$quarter = array(
1=>'1st Week',
2=>'2nd Week',
3=>'3rd Week',
4=>'4th Week');
$selected = is_null($selected) ? date('m') : $selected;
$select = '<select name="'.$id.'" id="'.$id.'">'."\n";
foreach($week as $key=>$quar)
{
$select .= "<option value=\"$key\"";
$select .= ($key==$selected) ? ' selected="selected"' : '';
$select .= ">$quar</option>\n";
}
$select .= '</select>';
return $select;
}
?>
<label><input type="radio" name="dw_sel" value = "month" id="month_select" onclick = 'createMonths("month_select",1)' /> month</label>
<label><input type="radio" name="dw_sel" value = "week" id="week_select" onclick = 'createWeek("week_select",1)' /> week</label>
<select size="1" id="dw_sel"></select>
here i need to put logic for example (i will appreciate any input or help in regards to this as well):
if month is selected and it is janurary then set and print red color else if february then set and print pink and so on.
as well if it is week and not month then if it is 1st week then set and print black....