/    Sign up×
Community /Pin to ProfileBookmark

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?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 16.2009 — Either[code=php]<?=$_GET['Contact0Email'];?>[/code]Or[code=php]<?php echo $_GET['Contact0Email']; ?>[/code]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.[code=php]<? echo $_GET['Contact0Email']; ?>[/code]

For your script tags, the normal syntax is&lt;script type="text/javascript"&gt;&lt;/script&gt;No language, just type. And obviously an src if necessary.
×

Success!

Help @legionarius spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...