Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript, escape the backslash

Posted on 2008-06-23
4
Medium Priority
?
2,775 Views
Last Modified: 2008-06-24
i am using a javascript function found here in ee.

it works nice to retrieve the querystring variables and later write them on the html page

i ran into a problem, and that is, when a passed variables contains a backslash such as:

p_old_path=\\PPT.DFT\Files\Global\My_Directory

the variables is written as

\PPT.DFTFilesGlobalMy_Directory  

how can the function be modified so it escapes the backslashes that are contained on the passed querystring variables?


Thank you.
<script language="javascript">
    p_name= "";
    p_id= "";
    p_old_path= "";
    p_new_path= "";
    p_dir_owner= "";
    p_primary_stew= "";
    p_bckup_stew= "";
    p_full_access= "";
    p_read_access= "";
    p_description= "";
    p_other_info= "";
// 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>

Open in new window

0
Comment
Question by:itortu
[X]
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
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 21851271
try:
 eval(tempArray[0] + " = \"" + tempArray[1].replace(/[\\]/g,'\\') + "\"");

Open in new window

0
 

Author Comment

by:itortu
ID: 21856231
i'm still not able to see the "\" written on the page :-(
0
 

Author Comment

by:itortu
ID: 21856485
i am pasting the contents of my page may be that helps?
<script language="javascript">
		p_name= "";
    p_id= "";
    p_old_path= "";
    p_new_path= "";
    p_dir_owner= "";
    p_primary_stew= "";
    p_bckup_stew= "";
    p_full_access= "";
    p_read_access= "";
    p_description= "";
    p_other_info= "";
		// 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>
	<script language="javascript">
	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 = ret.replace(/\\+/g, '\\');
    
    
    ret = decodeURIComponent(ret);
    ret = ret.toString();
    return ret;
		}			
  </script>		
  		<table border=0 width=600>
			<tr>
				<td width=300>
					<table>
						<tr><td class='label'>Name of Person Requesting Directory:</td></tr>
						<tr><td class='label'>0#XXX:</td></tr>
						<tr><td class='label'>Current Directory Path:</td></tr>
						<tr><td class='label'>New Path of Directory:</td></tr>
						<tr><td class='label'>Directory Owner:</td></tr>
						<tr><td class='label'>Primary Directory Steward:</td></tr>
						<tr><td class='label'>Directory Backup Steward:</td></tr>
						<tr><td class='label'>Full Access:</td></tr>
						<tr><td class='label'>Read Only Access Needed:</td></tr>
						<tr><td class='label'>Directory description:</td></tr>
						<tr><td class='label'>Other Information:</td></tr>
					</table>	
				</td>
				<td width=300>
					<table>
			   	   <tr><td class='label'><script language="javascript"> document.write(urldecode(p_name));</script>&nbsp;</td></tr>
             <tr><td class='label'><script language="javascript"> document.write(urldecode(p_id));</script> &nbsp;</td></tr>
             <tr><td class='label'><script language="javascript"> document.write(urldecode(p_old_path));</script> &nbsp;</td></tr>
             <tr><td class='label'><script language="javascript"> document.write(urldecode(p_new_path));</script> &nbsp;</td></tr>
             <tr><td class='label'><script language="javascript"> document.write(urldecode(p_dir_owner));</script> &nbsp;</td></tr>
						 <tr><td class='label'><script language="javascript"> document.write(urldecode(p_primary_stew));</script> &nbsp;</td></tr>
						 <tr><td class='label'><script language="javascript"> document.write(urldecode(p_bckup_stew));</script> &nbsp;</td></tr>
						 <tr><td class='label'><script language="javascript"> document.write(urldecode(p_full_access));</script> &nbsp;</td></tr>
						 <tr><td class='label'><script language="javascript"> document.write(urldecode(p_read_access));</script> &nbsp;</td></tr>
						 <tr><td class='label'><script language="javascript"> document.write(urldecode(p_description));</script> &nbsp;</td></tr>
						 <tr><td class='label'><script language="javascript"> document.write(urldecode(p_other_info));</script> &nbsp;</td></tr>
				  </table>
        </td>
      </tr>	       
		</table>
  
  

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 1200 total points
ID: 21857231
use this:

eval(tempArray[0] + " = \"" + tempArray[1].replace(/[\\]/g,'&#92;') + "\"");

Open in new window

0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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 …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

596 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