admin管理员组文章数量:1414614
I'm using an excellent jquery plugin for Birthday Date picking for my web form.
Demo here: /
The problem I'm dealing with is on a form validation. My form validation redirect back to the same page and I'll lose the date that was picked.
Is there any way to add an option to the javascript of the date picker: .js
so that I can set a "default selected date". The config can work to something like:
$("#picker1").birthdaypicker({
chosenDay: 1;"
chosenMonth: 28;"
chosenYear: 2011;"
});
This will set the "selected" date to January 28, 2011.
I'm using an excellent jquery plugin for Birthday Date picking for my web form.
Demo here: http://abecoffman./stuff/birthdaypicker/
The problem I'm dealing with is on a form validation. My form validation redirect back to the same page and I'll lose the date that was picked.
Is there any way to add an option to the javascript of the date picker: http://abecoffman./stuff/birthdaypicker/bday-picker.js
so that I can set a "default selected date". The config can work to something like:
$("#picker1").birthdaypicker({
chosenDay: 1;"
chosenMonth: 28;"
chosenYear: 2011;"
});
This will set the "selected" date to January 28, 2011.
Share Improve this question edited Mar 8, 2011 at 23:05 Abe 1617 bronze badges asked Jan 28, 2011 at 16:43 YadaYada 31.3k25 gold badges105 silver badges145 bronze badges 3- That plugin does not appear to support a selected date at initialization time. Perhaps you could modify it. – Pointy Commented Jan 28, 2011 at 16:46
- My js skill is limited. I'm looking to see how I would go about modifying it. – Yada Commented Jan 28, 2011 at 16:48
- I've updated the plugin to allow setting a default date. – Abe Commented Mar 22, 2011 at 6:43
2 Answers
Reset to default 3Without modifying the plugin you could use JQuery to set the values. The markup that the plugin generates looks like this:
<fieldset class='birthday-picker'>
<select class='birth-year' name='birth[year]'></select>
<select class='birth-month' name='birth[month]'></select>
<select class='birth-day' name='birth[day]'></select>
</fieldset>
So your JQuery would simply have to get a hold on those elements and set their value. You'd want to make sure you're setting a value that exists in the select list.
$('select.birth-year').val('my_year'); // 1980
$('select.birth-month').val('my_month'); // 1-12 (not "Jan" which is the text)
$('select.birth-day').val('my_day'); // 1-31 (keep month limitation in mind)
This code would have to be called after the plugin has been called, otherwise the markup won't have been generated yet.
If the server returns a date like this (c# code):
new DateTime(birthYear, birthMonth, birthDay, 0, 0, 0, DateTimeKind.Utc).ToString(CultureInfo.InvariantCulture);
On jquery-birthday-picker.min.js file you'll find a code like this:
if (s.defaultDate) {
var d = new Date(s.defaultDate);
console.log(d);
u.val(d.getFullYear());
a.val(d.getMonth() + 1);
f.val(d.getDate())
}
just change it for:
if (s.defaultDate) {
var d = new Date(s.defaultDate);
console.log(d);
u.val(d.getFullYear());
a.val(d.getMonth() + 1);
f.val(d.getDate())
//Added by LVC
$birthday.val(s.defaultDate);
}
Then, when you specify a defaultDate the control will work as as we want to
本文标签: javascriptjQuery Birthday Picker dealing with form refreshStack Overflow
版权声明:本文标题:javascript - jQuery Birthday Picker dealing with form refresh - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745165182a2645636.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论