4 Replies - 376 Views - Last Post: 28 January 2012 - 02:25 AM

Topic Sponsor:

#1 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

Problem in passing variables

Posted 28 January 2012 - 12:16 AM

this is a javascript query and there was no subforum for javascript so i posted here...please move to the right forum if possible...
hey im trying to pass values of javascript variables with the help of this code
location.href="myPage.php?Result=" + Result;


this is working fine but if i try to pass more than one variable something goes wrong and 0 is passed and 404 error comes
location.href="q.php?day=" + x &"month=" +y &"year=" +z;


i guess there is some minor syntax error here...please help if possible

Is This A Good Question/Topic? 0
  • +

Replies To: Problem in passing variables

#2 JavaIsForever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 27-January 12

Re: Problem in passing variables

Posted 28 January 2012 - 12:21 AM

Javascript is located in the "Web Development" section of this website, just so you know.
Also, just at a glance (Note it's been a long time since I've done any web development), but shouldn't the ampersands be inside the quotes?
location.href="q.php?day=" + x "&month=" +y "&year=" +z;

This post has been edited by JavaIsForever: 28 January 2012 - 12:23 AM

Was This Post Helpful? 2
  • +
  • -

#3 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

Re: Problem in passing variables

Posted 28 January 2012 - 12:23 AM

ok thanks!
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1758
  • View blog
  • Posts: 2,693
  • Joined: 08-June 10

Re: Problem in passing variables

Posted 28 January 2012 - 12:32 AM

You've got your & chars outside the strings. You want it to look like this:
"page.php?first=" + f + "&second=" + s + "&third=" + t


Also, if you don't already use it, check out the encodeURIComponent function. It makes sure variables passed into URLs don't mess the URL up by adding reserved characters as data.

P.S.
I've merged your two threads and move them to the Javascript forum. Try not to double post your questions, even if you post the first one in the wrong section. Just use the "Report" button to ask that it be moved.

This post has been edited by Atli: 28 January 2012 - 12:40 AM

Was This Post Helpful? 1
  • +
  • -

#5 JavaIsForever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 27-January 12

Re: Problem in passing variables

Posted 28 January 2012 - 02:25 AM

I finally got something right, and no rep?! Ah my life is over.
Was This Post Helpful? -2
  • +
  • -

Page 1 of 1