Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

JQuery Set date in url

Hi all,

I am using a JQuery plugin. What I basically need to do it to set a date from a link.

The way I set the date on a page load is the following:

<script language="javascript">
      $(document).ready(function() {
      
         var queryDate = ('2011-05-10');
        $('#date').val(queryDate);

....

I need to do the same but I need to create a link on page A and set it from there.

So, Page A link, links to this page and it sets the parameter.

something link: <a href="index.php?"mydate"">link to main page</a>

Does it make sense?

Thanks

Avatar of Zyloch
Zyloch
Flag of United States of America image

Attach the correct date to the end of your URL as part of the query string on Page A, e.g. index.php?date=###. On your other page, read in the date from the query string, either by parsing location.href yourself or making use of a jQuery plugin to do the parsing for you. Possible plugins include this and this.
Avatar of error77
error77

ASKER

OK, trying out this .. not working for some reason:

On page A I have:

<a href="index2.php?date=2011-2-10"> Link to date</a>

And on Page B:

<script language="javascript">
      $(document).ready(function() {
      
      var queryDate= $(document).getUrlParam('date');
        $('#date').val(queryDate);

What I'm I doing wrong please?

I have done some research, and it is not your fault. The plugin you are using works with jQuery 1.5 but does not work for some reason in jQuery 1.6. I tested the other one, and it appears to work.
Avatar of error77

ASKER

So, what do I change to make it work?
You need to replace the first plugin file, which you should be including on your page, with the script listed in the second link in my post. Then, a call to $.url.param("date") will work.
Avatar of error77

ASKER

OK, I've added the js file:

<script type="text/javascript" src="_includes/js/jquery.url.js"></script>

refreshed and tried again but it's still not working :o/

Please post your entire code.
Avatar of error77

ASKER

Page A has:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script type="text/javascript" src="_includes/js/jquery.url.js"></script>
...

<body>

...
<a href="index2.php?mydate=2011-2-10" rel="external"> Link here</a>


then page B

 in <head>

<script language="javascript">
      $(document).ready(function() {
      
      var mydate2 = $(document).getUrlParam('mydate');
      
         var queryDate = (mydate2);
        $('#date').val(queryDate);
        
      
            $("input[type='submit']").click(function(e) {
                  e.preventDefault();
            });
      });
      
</script>

Also in the form:

<input value="2011-01-01" name="date" type="date" data-role="datebox" id="date" data-theme="a" data-options='{"mode": "calbox", "pickPageTheme": "a", "pickPageHighButtonTheme": "e", "setDateButtonLabel": "Calendar"}'/>      


ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error77

ASKER

Works like a charm! Thanks!