Solved

Replace text on a page with other text

Posted on 2004-09-20
5
34,344 Views
Last Modified: 2011-08-18
Wondering if we can replace some text on a page after it finishes loading, maybe on document complete.
Maybe replace 12345 with 67890



<HTML>
<HEAD>
<TITLE>test</TITLE>
</HEAD>
<BODY>

<P>&nbsp;</P>
Replace this: 12345
</BODY>
</HTML>



Any Ideas?


Alan
0
Comment
Question by:Alan Warren
  • 2
  • 2
5 Comments
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
Hi alanwarren,

document.body.innerHTML=document.body.innerHTML.replace("/12345/","67890");

Regards,
Zyloch
0
 
LVL 6

Expert Comment

by:viola123
Comment Utility
this code replace the text when document complete

<html>
      <head>
            <title>Test</title>
      </head>
      <body>
            <div id="divtest">ffff</div>
      </body>
      <script language=javascript>
            document.getElementById("divtest").innerHTML = "eeeeeee";
      </script>
</html>
0
 
LVL 26

Author Comment

by:Alan Warren
Comment Utility
hmmm...

can't seem to get it happening, dont want to replace the entire contents of the div only occurences of '12345'
I do some class swapping to display/hide the div, this works fine, so I thought the place to insert the clientside replace was where I do the class swapping to display block.

heres a portion of my script:

  <script language="JavaScript" type="text/javascript">
    <!--
    function ToggleSourceAsp(){
      var f = document.frmSourceAsp;
      if (f.chkSourceAsp.checked){
        //show source
        document.getElementById("divSourceAsp").className = 'Visible';
        document.getElementById("lblSourceAsp").innerText = 'Hide source: ';
        document.getElementById("divSourceAsp").innerHTML.replace("12345","Password");
      }
      else{
        //hide source
        document.getElementById("divSourceAsp").className = 'Hidden';
        document.getElementById("lblSourceAsp").innerText = 'Show source: ';
      }
    }
    //-->
  </script>
  <FORM name='frmSourceAsp' id='frmSourceAsp'>
    <input
     type='checkbox'
     id='chkSourceAsp'
     onclick="ToggleSourceAsp()">
    <A id="lblSourceAsp">Show source: </A>
    <%
      Dim sThePageName
      sThePageName = Server.MapPath(Request.ServerVariables("PATH_INFO"))
      sThePageName = Mid(sThePageName, InStrRev(sThePageName, "\") + 1)
      Response.Write(sThePageName)
    %>
  </FORM>
    <Div id="divSourceAsp" name="divSourceAsp" class="hidden">
      <!-- #include file ="./ServerScript/Asp.render.asp" -->
      <%Call RenderAspScript(Server.MapPath(Request.ServerVariables("PATH_INFO")))%>
    </Div>



What I'm doing is rendering the source ASP in a PRE tag inside a Hidden DIV tag and toggling the display of the DIV by swapping styles when a checkbox is checked, the problem being that the ADO connect string password in the source ASP is being displayed too, hmmm.. Would like to swap this value if possible.



Alan
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
Comment Utility
Ah, but this line:
document.getElementById("divSourceAsp").innerHTML.replace("12345","Password");

It's only replacing the stuff, but not setting anything. You need this:

document.getElementById("divSourceAsp").innerHTML=document.getElementById("divSourceAsp").innerHTML.replace("12345","Password");
0
 
LVL 26

Author Comment

by:Alan Warren
Comment Utility
Cool as... LOL
Thanks for your help


Alan
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

772 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

8 Experts available now in Live!

Get 1:1 Help Now