Solved

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

Posted on 2013-01-04
6
251 Views
Last Modified: 2013-09-12
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
Comment
Question by:joibrooks
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:Randy Downs
ID: 38744766
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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38744782
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
 

Author Comment

by:joibrooks
ID: 38745087
@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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 82

Expert Comment

by:leakim971
ID: 38745119
Why do you put all this information?
Parameter in a URL must be separate by the << & >>
0
 

Author Comment

by:joibrooks
ID: 38745374
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
 

Author Comment

by:joibrooks
ID: 38745393
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now