SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using javascript to append text to a url

    I am trying to append a string to a url

    I have a variable set:

    Code JavaScript:
    var vLocate = "?country=1";

    and I would like to append this to a link:
    HTML Code:
    <a href="/somelink.html">Click Me</a>

    How can this be done? I have seen bits and pieces of code that rewrites the whole url but then it does not explain what is in the href.

    Thanks,

    Dan

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2008
    Location
    Asheville, NC
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    I believe you can get the link by adding an id to it and go:

    HTML Code:
    var myLink = document.getElementById('linkId');
    then, you can do this:

    HTML Code:
    myLink.href = myLink.href + vLocate;
    haven't tested it, but it should work.

  3. #3
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    trapach,

    That did it.

    Thanks,

    Dan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •