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
Solved

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

Posted on 2008-06-19
7
614 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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. …
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'…
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…

790 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