Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Capturing a referral ID in a web form as a hidden field
Old 01-17-2008, 03:24 AM Capturing a referral ID in a web form as a hidden field
Novice Talker

Posts: 6
Trades: 0
I am trying to capture a referral ID from a URL into a web form as a hidden field.

For example the landing URL would be: http://www.yoursite.com/inquiry.html?a_aid=38561bce

I need the form on that page to capture something like:
<input name="lead_source" value="38561bce" type="hidden">

I have tried this Javascript code, but it just doesnt want to do anything:
HTML Code:
<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];
}
}
}

</script>
<script type="text/javascript" language="JavaScript"><!--
document.write('<input ');
document.write(' type="hidden" ');
document.write(' name="lead_source" ');
document.write(' value="' + getQueryVariable("a_aid") + '">');
//--></script>
Does anybody have any other ideas? Thanks in advance.
DreamWeb is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-17-2008, 03:26 AM Re: Capturing a referral ID in a web form as a hidden field
Novice Talker

Posts: 6
Trades: 0
Also, I dont mind doing this in PHP or whatever else it's fine; doesnt need to be Javascript.
DreamWeb is offline
Reply With Quote
View Public Profile
 
Old 01-17-2008, 03:55 AM Re: Capturing a referral ID in a web form as a hidden field
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,520
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You can't "document.write" elements into forms
put the hidden input in the form and use
Code:
document.formname.hiddenElementName.value = getQueryVariable("key");
and at the basic PHP would be

HTML Code:
<input type="hidden" name="whatever" value="<?$_GET['keyname']?>">
although you should "sanitise" the querystring value first
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Capturing a referral ID in a web form as a hidden field
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30890 seconds with 12 queries