1

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

asked Sep 2, 2013 at 14:17
2
  • notice the semicolon after selecteddate variable replace it with + sign Commented Sep 2, 2013 at 14:22
  • 1
    Are you sure you want to pass the date in that format? You could use selecteddate.getTime() to pass it in milliseconds. Commented Sep 2, 2013 at 14:23

3 Answers 3

2

Your syntax is off. Plus you should encode it:

location.href = "/home?selected_date=" + encodeURIComponent(selecteddate) + "&days_ago=" + encodeURIComponent(dateDiff(selecteddate , todaysdate));
answered Sep 2, 2013 at 14:19
Sign up to request clarification or add additional context in comments.

2 Comments

@Sergio yep, without it the URL will still be broken. :)
@ShadowWizard I think it should be encodeURIComponent not encodeUriComponent if I am not wrong
0

you missed to concatenate.

location.href = "/home?selected_date="+selecteddate+";&days_ago="+dateDiff(selecteddate , todaysdate);
answered Sep 2, 2013 at 14:19

Comments

0

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.

answered Sep 2, 2013 at 14:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.