Solved

Replace text on a page with other text

Posted on 2004-09-20
5
34,352 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
ID: 12109499
Hi alanwarren,

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

Regards,
Zyloch
0
 
LVL 6

Expert Comment

by:viola123
ID: 12109516
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
ID: 12109626
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
ID: 12109646
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
ID: 12109675
Cool as... LOL
Thanks for your help


Alan
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

856 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