Solved

decode a URL with excaped characters

Posted on 2014-03-04
6
215 Views
Last Modified: 2014-03-05
Experts were instrumental in supplying me with a solution. There were some developmental updates to the backend of my ESP, and so I'm returning for help.

Here's my initial post with your solution ==>
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27985181.html

Here's the page on the web that is functional ==>
http://e.openmoves.com/profiles/preference-center.html

Use the following URL to sample "functionality" ==>
http://e.openmoves.com/profiles/preference-center.html?email=billgates%40hotmail.com

As I note, the page is functional, except the value of my variable (email=@email@) has been changed. I am collecting data from my email service provider (ESP) to complete the input value for "email". The "@" symbol in the address has been replaced with "%40". I need to unescape that to submit the proper information.

I much appreciate your help. If you cannot extract the javascript form the page I provided, I will gladly send it separately.

Thank you,
JB
0
Comment
Question by:joibrooks
  • 3
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39904829
var a = decodeURIComponent("billgates%40hotmail.com");

alert( a ); // billgates@hotmail.com
0
 
LVL 58

Expert Comment

by:Gary
ID: 39904831
To decode with js use
decodeURIComponent(string)

But I don't see what this has to do with js, this is something you should be doing at the server...
0
 

Author Comment

by:joibrooks
ID: 39906177
@cathal:
our ESP recently changed the way they return their values. in a trouble ticket that i opened to alert them of the problem, they responded:
"In the following URL, the %40 is actually the correct value and is how the internet is supposed to work. It's called URL encoding."

@cathal and @leakim971:
 i found the decodeURIComponent method online, but I'm not certain how to implement it within my existing javascript. this is where i need your help. please.

the follow script is how i am retrieving the data from the url and placing the value into the email input field.

<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("emailaddress").value = gup("email");
    document.getElementById("emailaddress2").value = gup("email");
}
</script>

Open in new window


i much appreciate your help.
jb
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39906181
<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("emailaddress").value = decodeURIComponent( gup("email") );
    document.getElementById("emailaddress2").value = decodeURIComponent( gup("email") );
}
</script>

Open in new window

0
 

Author Comment

by:joibrooks
ID: 39906326
@ leakim971
thank you for another job well done.

jb
0
 

Author Closing Comment

by:joibrooks
ID: 39906337
would i love to go back to school to learn javascript? yes. do i have the time? no. your services are priceless and i recommend experts-exchange often.

jb
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

861 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