homepage Welcome to WebmasterWorld Guest from 54.166.84.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Managing Long Drop Down Lists
Long drop down lists
naiquevin

5+ Year Member



 
Msg#: 3874284 posted 2:37 pm on Mar 19, 2009 (gmt 0)

I want to allow users to select their Date of Birth using 3 drop down lists. Date/Month/ Year.
The Year list will be really long .. 1900 -2009 ..
So does it mean that I ll have to write the option tags 110 times!
Or is there a shortcut method available for this ?

Also, if I chose to keep these drop down lists in 3 separate files and include them in the form, will there be any problem in passing the variables using the post method ?

Thanks !

 

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3874284 posted 3:55 pm on Mar 19, 2009 (gmt 0)

There is a shortcut - copy and paste. :-) But better yet, you reveal . . .

...and include them in the form, will there be any problem in passing the variables using the post method

... that you have some access to server-side programming. I'll guess at PHP. Short answer, sure you can do that, but then your lists are hard-coded. There's a better way; this is not "working code" but gives you the idea:

$year_start = '1900';
$year_end = '2009';
$ddName = 'birth'; // or convert from input variables
// What you REALLY should do is get the current year
// dynamically and use that for year end.

$moName = $ddName . '_month';
$daName = $ddName . '_day';
$yrName = $ddName . '_year';

// Do some stuff here to set the values for $mm, $dd,
// $yyyy so you can set "selected" if it's present


$dtString = "
<select name=\"$moName\" id=\"$moName\">
<option value=\"\">--</option>
";
for ($i=1;$i<=12;$i++) {
$moTxt = (strlen($i)<2)?'0' . $i:$i;
$dtString .= "<option value=\"$moTxt\"";
if ($mm == $moTxt) { $dtString .= ' selected'; }
$dtString .= ">$moTxt</option>\n";
}
$dtString .= "
</select>
";

//(rinse and repeat for DAY, using 1-31)


$dtString .= "
<select name=\"$yrName\" id=\"$yrName\">
<option value=\"\">--</option>
";
for ($i=$start_year;$i<=$end_year;$i++) {
$dtString .= "<option value=\"$i\"";
if ($yyyy == $i) { $dtString .= ' selected'; }
$dtString .= ">$i</option>\n";
}
$dtString .= "
</select>\n";

Now output $dtString and you have your date selects . . . . apply the same concepts for a time list.

dreamcatcher

WebmasterWorld Senior Member dreamcatcher us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3874284 posted 8:58 am on Mar 22, 2009 (gmt 0)

Another alternative would be a small javascript calendar that pops up when a form field is clicked. This eliminates 3 drop downs and makes things nice and tidy.

dc

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved