www.webdeveloper.com
Results 1 to 2 of 2

Thread: Query String var into javscript

  1. #1
    Join Date
    Jun 2008
    Posts
    16

    Query String var into javscript

    Hello all, essentially i am grabbing a variable from the query string and i need to pass that value into another script. allow me to explain;

    usually i use this code to display a persons email address from the query string onto the page using document.write

    <script>
    function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
    return pair[1];
    }
    }
    document.write('');
    }
    </script>


    then i would display the var with this

    <script> document.write( getQueryVariable("Contact0Email") ); </script>

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


    ok so here is what i need to do. my client sent me the code below asking me to pass the email var into the javascript and image. my programmer friend said to use php and do smething like;

    <SCRIPT language="javascript" src="https://www.cpctrack.com/redirconsume.aspx?CID=25240&ORDERID=<? echo . $_GET['Contact0Email']; ?>"></SCRIPT>

    <NOSCRIPT><IMG src="https://www.cpctrack.com/redirconsume.aspx?CID=25240&p=img&ORDERID=<? echo . $_GET['Contact0Email']; ?>" width="1" height="1" border="0"></NOSCRIPT>

    this syntax does not work;

    <? echo . $_GET['Contact0Email']; ?>

    WHAT DO YOU GUYS THINK? Is the syntax wrong or are there better methods?

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Either
    PHP Code:
    <?=$_GET['Contact0Email'];?>
    Or
    PHP Code:
    <?php echo $_GET['Contact0Email']; ?>
    Latter is guaranteed to work, former may or may not depending on server settings. I think that the problem you have is the dot between echo and $, I think this would also work.
    PHP Code:
    <? echo $_GET['Contact0Email']; ?>
    For your script tags, the normal syntax is
    Code:
    <script type="text/javascript"></script>
    No language, just type. And obviously an src if necessary.
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles