Replace function not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • techbytes
    New Member
    • May 2010
    • 36

    Replace function not working

    In my project,iam passing file path as a parameter to a javascript function.

    On replacing the separator with escape character, iam passing this parameter to another function that is called in my previous function.
    But in my second function, iam getting the blank spaces without the separator.

    Code:
    function linkFolderHTML(isTextLink) 
    { 
      var docW = "";
        
        
    
        var str =this.hreference; //PATH "E:\XX\test";
        var xy = str.replace('\\','\\\\');
        
      if (this.hreference) 
      {
         
    	if (USEFRAMES)
               
    	 // docW = docW + "<a href='" + this.hreference + "' TARGET=\"_self\" "
                docW = docW + "<a href='javascript:ajaxDisplay(\""+xy+"\",\""+this.getID()+"\")' TARGET=\"_self\" "
    	else
    	//  docW = docW + "<a href='" + this.hreference + "' TARGET=\"_self\" "
                docW = docW + "<a href='javascript:ajaxDisplay(\""+xy+"\",\""+this.getID()+"\");' TARGET=\"_self\" "
            
        if (isTextLink) {
            docW += "id=\"itemTextLink"+this.id+"\" ";
        }
    
        docW = docW + ">"
      } 
      else 
        docW = docW + "<a>" 
      return docW;
    } 
    
    
    
     function ajaxDisplay(path,id)
    {
      alert(path); //iam getting "E:XX test"
      searchReq.open('GET','../jsppages/displaylist.jsp?path='+pathx);
      // searchReq.open('GET','../jsppages/treeview.jsp?mode=display&path='+pathx);
        searchReq.onreadystatechange = function()
                {
                  DisplayReply(divid);
                };
            searchReq.send(null);
    
    }
    Attached Files
    Last edited by Niheel; Aug 24 '11, 05:44 AM. Reason: use code tags, easier than downloading files.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if this.hreference is assigned "E:\XX\test "; then the replace statement won’t work because in str the escaping is already executed, i.e. str = "E:XX est";. use encodeURICompon ent() to prepare the string for URL transmission.

    Comment

    Working...