Solved

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

Posted on 2013-01-04
6
253 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

803 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