Solved

JavaScript, firefox 2.0.0.14, IE 7, Remove '%' sign from querystring variable

Posted on 2008-06-19
7
613 Views
Last Modified: 2010-05-18
hello,

I have a problem with a variable that comes from a querystring request.

the name of the variable is:

p_flight

and it could contain 4 different values:

7 a.m. CID to MSN
8 a.m. MSN to CID
4 p.m. CID to MSN
5 p.m. MSN to CID

this variables are passed from a web html form to a perl script that redirects to a success html page with a javascript function that retrieves the variables from the url to display in the success page.

all the variables work fine, but the ones that contain spaces in between on word and another are being displayed with the '%' sign.

is there any way i can remove the sign after the variables is retrieved?

any help would be great.

thank you.
this is the success page:
 
<html>
<head>
<title>Success Page</title>
<script language="javascript">
 
p_name = "";
p_date = "";
p_flight = "";
p_cancel_by = "";
p_emp_number = "";
p_emp_email = "";
 
// Get names
var queryString = window.location.href.substring((window.location.href.indexOf('?') + 1));
var array1 = queryString.split('&'); // Each array element is in format "fieldname=value"
for(var i = 0; i < array1.length; i++){
 var tempArray = array1[i].split('='); // Separate fieldname and value
 eval(tempArray[0] + " = \"" + tempArray[1] + "\"");
}
 
</script>
</head>
<body>
<p>
<script language="javascript"> document.write(p_name);</script> 
<script language="javascript"> document.write(p_date);</script> 
<script language="javascript"> document.write(p_flight);</script> 
<script language="javascript"> document.write(p_cancel_by);</script> 
<script language="javascript"> document.write(p_emp_number);</script> 
<script language="javascript"> document.write(p_emp_email);</script> 
</p>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:itortu
  • 4
  • 3
7 Comments
 
LVL 2

Assisted Solution

by:kszurek
kszurek earned 300 total points
ID: 21822406
0
 

Author Comment

by:itortu
ID: 21822478
but my page is html not php
0
 

Author Comment

by:itortu
ID: 21822496
oh sorry i see it is javascript.

would you be able to show me how to add this function into my current functionality?

i don't want to mess anything up.
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 2

Accepted Solution

by:
kszurek earned 300 total points
ID: 21822507
This code is in Java Script
function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    
    var ret = str;
       
    ret = ret.replace(/\+/g, '%20');
    ret = decodeURIComponent(ret);
    ret = ret.toString();
 
    return ret;
}

Open in new window

0
 
LVL 2

Assisted Solution

by:kszurek
kszurek earned 300 total points
ID: 21822528
Try:
<script language="javascript"> document.write(urldecode(p_name));</script>
0
 

Author Comment

by:itortu
ID: 21822529
got it

<tr><td class="label"><script language="javascript"> document.write(urldecode(p_flight));</script> </td></tr>                                                                                                                                                                                            
0
 

Author Comment

by:itortu
ID: 21822532
ops you reply just before I did.

anyhow, it di work very nice.

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

770 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