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
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"">
Does it make sense?
Thanks
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.
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('d ate');
$('#date').val(queryDate);
What I'm I doing wrong please?
On page A I have:
<a href="index2.php?date=2011
And on Page B:
<script language="javascript">
$(document).ready(function
var queryDate= $(document).getUrlParam('d
$('#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.
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.
ASKER
OK, I've added the js file:
<script type="text/javascript" src="_includes/js/jquery.u rl.js"></s cript>
refreshed and tried again but it's still not working :o/
<script type="text/javascript" src="_includes/js/jquery.u
refreshed and tried again but it's still not working :o/
Please post your entire code.
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.u rl.js"></s cript>
...
<body>
...
<a href="index2.php?mydate=20 11-2-10" rel="external"> Link here</a>
then page B
in <head>
<script language="javascript">
$(document).ready(function () {
var mydate2 = $(document).getUrlParam('m ydate');
var queryDate = (mydate2);
$('#date').val(queryDate);
$("input[type='submit']"). click(func tion(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"}'/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script type="text/javascript" src="_includes/js/jquery.u
...
<body>
...
<a href="index2.php?mydate=20
then page B
in <head>
<script language="javascript">
$(document).ready(function
var mydate2 = $(document).getUrlParam('m
var queryDate = (mydate2);
$('#date').val(queryDate);
$("input[type='submit']").
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":
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm! Thanks!