how to show Datebox calendar in jquery-mobile when clicking a button

Bader picture Bader · Nov 16, 2011 · Viewed 9.7k times · Source

I don't want to have a date text field, just i want to pop up Datebox (calendar) only when the user clicks on a button ..

this code that i found ..

<input name="mydate" id="mydate" type="date" data-role="datebox" data-options='{"mode": "calbox"}'>

but I don't want a text field. only button to show a calendar

Answer

Phill Pafford picture Phill Pafford · Nov 16, 2011

Does this work for you?

JS

$('#linkmodelink').live('click', function() {
    $('#linkmode').datebox('open');
});

HTML

<div data-role="fieldcontain">
    <label for="linkmode">Some Date</label>
    <input name="linkmode" type="date" data-role="datebox" id="linkmode" data-options='{"noButton": true}' />
</div>
<br />
<a href="#" id="linkmodelink" data-role="button">Click Here</a>

I've just used the 'Open on Link' example here:

and added the data-role="button" to the anchor tag making jQM add the button markup