Solved

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

Posted on 2008-06-19
7
612 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now