1

I'm playing around with the UI datepicker widget and I noticed that when the calender is generated, all the dates are inside an anchor tag with href="#". is it possible to change the href to the dateText, or whatever i set the dateFormat to?

ex: <a class="ui-state-default" href="#October-27-2010">27</a>

Thanks in advance

//update

any clues on how to do this?

Gerald
  • 23
  • 2
  • 7

2 Answers2

0

I don't see any answer to this and this is a very old question. However, for future reference and incase anyone comes across this problem.

You need to do (in the example below I've used http://localhost:3000/ this is the url my page was on, yours will/could be different. For example: http://www.myamazingsite.com/homepage/):

window.location.href = "http://localhost:3000/" + this.value;

Below is my full code snippet which is working perfectly for me. I read and reference from the Jquery ui Datepicker docs (http://api.jqueryui.com/datepicker/) and also, after research more examples came across this already answered on stackoverflow which extremely similar to what i've done: (Calendar change URL on select with jQuery UI datepicker).

  $("#datepicker")
    .datepicker({
      defaultDate: parsedDate,
      beforeShowDay: $.datepicker.noWeekends,
      dateFormat: "yy/mm/dd",
      onSelect: function(parsedDate) {
        $(this).change();
      }
    })
    .change(function() {
      window.location.href = "http://localhost:3000/" + this.value;
    });

Lastly, the parsedDate is a variable I created above

var parsedDate = $.datepicker.parseDate('yy/mm/dd');

Steps: 1: You need to use an OnSelect event for when you select one of the Jquery UI's dates. 2. You need to do: window.location.href which is used to redirect the page.

Community
  • 1
  • 1
pourmesomecode
  • 4,108
  • 10
  • 46
  • 87
0

I suppose you can in this case.

Why would you want to change the href? The datepicker links work with an click-event, so when the link is clicked it won't use the href but it executes the javascript first. And if this script returns false, the href-attribute will never be read (which probably is the case because the URL doesn't get the "#" at the end).

If the script returns true, the link will be executed.

Google will read those links, though, if they lead somewhere (because the indexing-robots ignore javascript as far as I know). Is that what you want to achieve?

Justus Romijn
  • 15,699
  • 5
  • 51
  • 63
  • I've been given an old events calendar with anchors spread throughout. I thought it would be nice to use this datepicker to navigate through those anchors. Rather than build a calendar from scratch, and constantly have to update it. also, I'm not concerned with google reading these links. – Gerald Oct 19 '10 at 14:05