SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing variables in href tag

    --------------------------------------------------------------------------------

    What is the correct syntax for passing variables in a href tag when the href is outside of the javascript tags? I believe it is not recognizing the href because it is not reading the variables: boxid & projectname. Please advise.

    *******************************************************


    <script type="text/javascript" language="javascript">

    var linkURL = '';
    var boxid = '';
    var changeLinkURL = '';


    function getUrlVars()
    {
    var vars = [], boxid;
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
    vars[key] = value;
    });
    return vars;
    }

    function PassQueryString()
    {
    boxid = getUrlVars()["boxid"];
    projectName = getUrlVars()["project"];
    alert("ParseQueryString - BoxID :" + boxid);
    alert("ParseQueryString - ProjectName :" + projectName);

    }
    function changeLinkURL()
    {
    boxid = getUrlVars()["boxid"];
    projectName = getUrlVars()["project"];
    linkURL = "C:\Users\Geri\Desktop\test_1.htm + "?boxid=" + boxid + "&projectName=" + projectName";
    }
    function Project(pname)
    {
    location.href=menuURL[pname];
    }


    </script>


    <script type="text/javascript">
    var first = getUrlVars()["boxid"];
    var second = getUrlVars()["project"];
    alert("back button : " + "" + first);
    alert("back button : " + "" + second);
    </script>



    <a href="C:\Users\Geri\Desktop\test_1.htm?boxid=DBB&amp;project=projectName">


    <IMG style="BORDER-BOTTOM: 0px solid;
    BORDER-LEFT: 0px solid; BORDER-TOP: 0px solid; BORDER-RIGHT: 0px solid" border=0
    alt="Back Button" src="C:\Users\Geri\Desktop\test_1.htm/Back%20Button/back_button1.gif">
    </A></P>

    </a>

    <body>
    </body>
    </html>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    You have some syntax errors in there. Most especially with this line:

    Code:
    linkURL = "C:\Users\Geri\Desktop\test_1.htm + "?boxid=" + boxid + "&projectName=" + projectName";
    Also, the slashes in that string should be escaped too.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •