I am a ruby on rails developer and have a simple question which I am not able to figure out.
location.href = "/home?selected_date="+selecteddate;"&days_ago="+dateDiff(selecteddate , todaysdate);
I have to generate a URL by using the above code, here I have a variable called selecteddate which generates a value and dateDiff(selecteddate , todaysdate); does a difference of the selected date and today's date and gives me a value.
Question: When I execute it my URL looks like this:
/home?selected_date=Sun Sep 01 2013 00:00:00 GMT+0530 (IST)
I am missing the &days_ago= part. Any Idea how parse two parameters in the URL.
Thanks you in advance
-
notice the semicolon after selecteddate variable replace it with + signTahir Yasin– Tahir Yasin2013年09月02日 14:22:21 +00:00Commented Sep 2, 2013 at 14:22
-
1Are you sure you want to pass the date in that format? You could use selecteddate.getTime() to pass it in milliseconds.bfavaretto– bfavaretto2013年09月02日 14:23:22 +00:00Commented Sep 2, 2013 at 14:23
3 Answers 3
Your syntax is off. Plus you should encode it:
location.href = "/home?selected_date=" + encodeURIComponent(selecteddate) + "&days_ago=" + encodeURIComponent(dateDiff(selecteddate , todaysdate));
you missed to concatenate.
location.href = "/home?selected_date="+selecteddate+";&days_ago="+dateDiff(selecteddate , todaysdate);
Comments
Try this code:
location.href = "/home?selected_date="+selecteddate+"&days_ago="+dateDiff(selecteddate , todaysdate);
The problem is that you're not concatenate the selecteddate string variable.