Passing a var from javascript into a url on a web page

Discussion in 'JavaScript' started by rainmanjam, Aug 23, 2008.

  1. #1
    I have a variable that is in my javascript code. I would like to
    create a url with variables from javascript to pass to another page.

    Example:

    http://www.bla.com/test.aspx?var1="jsvar1"&var2="jsvar2" etc.

    What would be the best way of doing this?
     
    rainmanjam, Aug 23, 2008 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    hmm, i dont fully understand but if you use the js for redirection you can probably use

    window.location ="yourintendedpage.htm?jsvar="+jsVarValue+"&jsvar2="+jsvar2Value and so on...
     
    serialCoder, Aug 23, 2008 IP
  3. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep, you can do it that way either for redirection or a http request.
     
    xlcho, Aug 24, 2008 IP
  4. rainmanjam

    rainmanjam Peon

    Messages:
    155
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm trying to compose the following url

    <a href=http://www.bla.com/test.aspx?var1="jsvar1"&var2="jsvar2"onclick="hidePopupMenu();">Mark</a>
     
    rainmanjam, Aug 24, 2008 IP
  5. vipinc007

    vipinc007 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    window.location.href="page.html?var1="+var1;
     
    vipinc007, Aug 25, 2008 IP
  6. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    As said earlier, to concatenate strings in javascript you must use + (plus sign). Just like you do it with a . (dot) in PHP. So, your code will have to be:
    <a href=http://www.bla.com/test.aspx?var1="+jsvar1+"&var2="+jsvar2+" onclick="hidePopupMenu();">Mark</a>
    Code (markup):
     
    xlcho, Aug 25, 2008 IP