I am trying to make a button change the text or value of my datebox form. The value will change if I call $(“element”).val(“value-date”) but the form that contains the datebox will not change its text to the value-date. I have refreshed the datebox and that has not worked.
Here is my code
HTML:
<div class='container center' style='margin-top:15%; margin-bottom:15%; width:90%; margin-right:auto; margin-left:auto;'>
<input placeholder="Enter Date" id='comp_date' type='date' data-role='datebox' name='date' data-options='{"mode": "callbox","useTodayButton":true}'/>
<a data-role="button" id='pick_today' href="#" data-theme='e' class="reg_button" style="padding:15px; color:black; margin-bottom:50px;">Now</a>
</div>
Javascript:
$("#pick_today").live("vclick",function()
{
var today = new Date();
var month = today.getMonth();
var day = today.getDate();
var year = today.getFullYear();
var todayText = year + "-" + month + "-" day;
$("#comp_date").val(todayText);
$("#comp_date").datebox("refresh");
}
After a long time spent on this issue, finally got and fixed your problem.
Your code issues are:
Symbol
"+"is missing on this linevar todayText = year + "-" + month + "-" + day;On the input tag, mode is
calboxnotcallboxdata-options='{"mode": "calbox"Month calculation should be
+1. Since January starts withZero (0)var month = today.getMonth()+1;JQuery:
HTML:
USED CSS & JS:
Refer my LIVE DEMO