Solved

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

Posted on 2013-01-04
6
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 30

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

726 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