Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Simple javascript that loads a URL variable into a form input tag

I'm sending an email campaign. There will be a link from the email campaign that sends subscribers to a landing page. The landing page link from the email will include the email address of the subscriber through a variable. Something like this:
http://www.URL.com/?EMAIL=@EMAIL@

The landing page will have a single input field and a submit button. I'd like to pre-populate that field with the email address from the URL using javascript.

How can I do this?
0
joibrooks
Asked:
joibrooks
  • 3
  • 2
1 Solution
 
Randy DownsOWNERCommented:
Try this
http://stackoverflow.com/questions/4877966/pass-a-simple-url-variable-into-and-input-field-via-javascript

document.getElementById("input_id").value = location.search.replace('?','');

Open in new window

0
 
leakim971PluritechnicianCommented:
use this gup function for example : http://snipplr.com/view/9275/

and use :
window.onload = function() {
    document.getElementById("YOUR_INPUT_FIELD_ID").value = gup("EMAIL");
}
0
 
joibrooksAuthor Commented:
@leakim971 that worked except I'm getting too much information passed through. This was in the input field:

myemail@address.com%3fEMAIL%3d%40EMAIL%40

How can I strip the rest of the information out? Sample of the code I used is attached.

<script language="javascript">
var gup = function( name ) {
    var results = (new RegExp("[\\?&]"+name+"=([^&#]*)")).exec(window.location.href);
    if ( results == null ) {return ""}
    else {return results[1]}
};

window.onload = function() {
    document.getElementById("emailaddie").value = gup("EMAIL");
}
</script>

Open in new window


Thank you!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leakim971PluritechnicianCommented:
Why do you put all this information?
Parameter in a URL must be separate by the << & >>
0
 
joibrooksAuthor Commented:
It looks like the script is not parsing the data that includes and follows the << ? >>.


So, in this URL...
http://www.URL.com/?EMAIL=@EMAIL@

The script is capturing:
myemail@address.com%3fEMAIL%3d%40EMAIL%40

%3fEMAIL%3d%40EMAIL%40 is equal to ?EMAIL=@EMAIL@

Have I made myself clear?
0
 
joibrooksAuthor Commented:
Hold on! I've found the error. You were correct in asking me why so much info. There was a typo. The solution is fine! Thank you!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now