JQuery Set date in url

error77
error77 used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004

Commented:
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.

Author

Commented:
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?

Top Expert 2004

Commented:
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.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
So, what do I change to make it work?
Top Expert 2004

Commented:
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.

Author

Commented:
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/

Top Expert 2004

Commented:
Please post your entire code.

Author

Commented:
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"}'/>      


Top Expert 2004
Commented:
The script
<script type="text/javascript" src="_includes/js/jquery.url.js"></script>

Open in new window

should be included in Page B.

Your code in Page B should remove the reference to mydate2 and just have
var queryDate = $.url.param("date");
$('#date').val(queryDate);

Open in new window

Author

Commented:
Works like a charm! Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial