• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1627
  • Last Modified:

Javascript Replace Method on innerHTML

I am trying to replace certain character strings found in the innerHTML and then once changed, write it out to a new HTML page.  
Here is my function which I invoke from a button onClick event:
function printPlanList(id) {
    var disp_setting="toolbar=no,location=no,directories=no,menubar=no,";
    disp_setting+="scrollbars=yes,width=820, height=450, left=100, top=25";
    var content_vlue = new String(eval("document.getElementById('"+id+"').innerHTML"));
    content_vlue.replace(/assignpicn/g, "assignpicp");  // make pics visible
    content_vlue.replace(/ztextview/g, "clickDummy");   // disable visibility function
    content_vlue.replace(/button/g, "hidden");          // make buttons invisible
    var docprint=window.open("","",disp_setting);
   docprint.document.open();
   docprint.document.write('<html><head><title>Print Plan</title>');
   docprint.document.write("\n");
   docprint.document.write('<STYLE type=text/css media=all>');
   var css = "@import url('css/mystyles.css');";
   docprint.document.write(css);
   docprint.document.write('</STYLE>');
   docprint.document.write("<script language='javascript' src='javascript/zcommon.js' type='text/javaScript'>");
   docprint.document.write("</script>");
   docprint.document.write("<script language='javascript' src='javascript/zplan.js' type='text/javaScript'>");
   docprint.document.write("</script>");
   docprint.document.write('</head><body onLoad="self.print()">');
   docprint.document.write(content_vlue);
   docprint.document.write('</body></html>');
   docprint.document.close();
   docprint.focus();
}

It is working to open the new window and to write the contents, except the REPLACE methods I am using does not change any of the string text I want.  Any ideas on how to perform this function?
0
mamuscia
Asked:
mamuscia
  • 3
  • 2
  • 2
1 Solution
 
Ashish PatelCommented:
Yes please reload the window document again and it should come.
0
 
mamusciaAuthor Commented:
I don't understand your answer.  I am changing the contents of the HTML prior to writing it to the new window so when I do the writes it should be the changed text already.  I'm not sure why the Javascript replace method isn't working on the string contents I put into the content_vlue string from the innerHTML contents.  

Why does it only work if I Reload the page?
0
 
Ashish PatelCommented:
So did you try reloading and did it work after reload?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
b0lsc0ttCommented:
I see one error in what you have ...

    content_vlue = content_vlue.replace(/assignpicn/g, "assignpicp");  // make pics visible
    content_vlue = content_vlue.replace(/ztextview/g, "clickDummy");   // disable visibility function
    content_vlue = content_vlue.replace(/button/g, "hidden");          // make buttons invisible

Let me know how that change works.

bol
0
 
mamusciaAuthor Commented:
I did try ReLoad and the same HTML is present and no changes were made to the HTML string contents.


Geeze - how dumb.  I did the solution that you outlined and it works like a charm.  I needed to assign the value of content_vlue to the new value after replacing the strings.

0
 
mamusciaAuthor Commented:
thanks
0
 
b0lsc0ttCommented:
:D  Your welcome!  It is an easy mistake to make, especially if you usually write the result of the replace() or use other languages.

I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now