12

I need to show jQuery UI datepicker on link click, also when a date is picked change link text to this date, how can I do it?

6 Answers 6

18

jQuery UI date picker should do the job.

Check out the example using an icon to trigger the picker: http://jqueryui.com/demos/datepicker/#icon-trigger

You can also call the show() method to drop down the picker whenever you need to, e.g...

$('#mypicker').datepicker({
      //options
      minDate: '20.04.2012'
      //...
    });
$('#mylink').click(function(){
      $('#mypicker').datepicker('show');
    });

To change the link text after a date is selected, use something like this in initialization code:

$('#mypicker').datepicker({ onSelect:
    function(dateText, inst) {
        $('#mylink').text(dateText);
    }
});
Sign up to request clarification or add additional context in comments.

9 Comments

yes, I'm using this datepicker, but I need it to appear on text link click, not input and not button/image, can't find how to do it.
How can I call show() method? I'm not very good in JavaScript, thanks
What is #mypicker in this case?
The id of the input element that you initialise as a datepicker. In jQuery examples (follow the links I gave you) it would be '#datepicker'
I'm trying this code : ` $(function() { $( "#datepicker" ).datepicker(); $('#mylink').click(function(){ $('#datepicker').show(); }); })` but it is not working. I have hidden input with id="datepicker" and link with id="mylink"
|
1
$("#dateField").datepicker({
 dateFormat:'dd/M/yy',
 minDate: 'now',
 changeMonth:true,
 changeYear:true,
 showOn: "focus",
 //buttonImage: "YourImage",
 buttonImageOnly: true, 
 yearRange: "-100:+0",  
}); 

$("dateField").datepicker( "option", "disabled", true );

Comments

1

This worked for me. Needs jquery-ui .ls and .css.

 $( function() {
            $( "#from" ).datepicker({
                changeMonth: true,
                changeYear: true
            });
            $( "#to" ).datepicker({
                changeMonth: true,
                changeYear: true
            });

Comments

0

Well, may be it's to late to reply in this post, but here is a great solution from Andrew in a similar thread, which works in 2015.

In a few words you need to put hidden input right after link and an empty div. The last one will do the trick.

Besides, there will no need in link click event.

Comments

0

This worked for me :

$('#dateinterval').click();

Comments

-1

Salam

I discover this solotion :

onclick="jQuery('#elementid').datetimepicker();jQuery('#elementid').datetimepicker('show');"

And work properly.

Sincerely yours.

Alireza Balvardi

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.