First we will do the basic form of datepicker. Here’s the code
datepicker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| < html > < head > < script type = "text/javascript" src = "js/jquery-1.7.1.min.js" ></ script > < script type = "text/javascript" src = "js/jquery-ui-1.8.17.custom.min.js" ></ script > < link rel = "stylesheet" type = "text/css" < script type = "text/javascript" > $(document).ready(function(){ $("#date").datepicker(); }); </ script > </ head > < body > < form method = "post" action = "" > Date of Birth : < input type = "text" name = "date" id = "date" /> </ form > </ body > </ html > |
quite awesome right?
Don’t be easily satisfied. If we look more detail into the datepicker we have created, it will be difficult for everyone to change the year and the month to their birth day as they have to scroll right or left continuously. So what is the solution?, easy enough. Just add 2 Options of the datepicker that are changeMonth and changeYear so now the function is looks like this
1
2
3
4
5
6
| $(document).ready( function (){ $( "#date" ).datepicker({ changeMonth: true , changeYear: true }); }); |
Hmm satisfied now? not yet!. Look at the year options of datepicker now. It only has 10 years back and 10 years next from now (2013). This is truly a big mistake hahaa.. 90’s people can’t use this app :D. Just calm down my friends, all we need to do is adding yearRange option.
Say we want to have 100 years back and no year next, we use this piece of code
1
| yearRange: "-100:+0" |
1
2
3
4
5
| $( "#date" ).datepicker({ changeMonth: true , changeYear: true , yearRange: "-100:+0" }); |
Wow 1913, are you gonna use this year? :P
The last option we will learn is dateFormat. As you already know, not all countries use the same date format. So we as the developers have to fit it. For date format here’s one of the example
1
2
3
4
5
6
| $( "#date" ).datepicker({ changeMonth: true , changeYear: true , yearRange: "-100:+0" , dateFormat: "dd MM yy" }); |
after using dateFormat
Okay, after we learnt about datepicker now we can develop web app using this help to better date input.
see you on next cool tutorial :D
Referensi : http://phpseason.wordpress.com/2013/02/14/jquery-ui-datepicker-tutorial/
0 comments:
Post a Comment