?
Solved

Replace text on a page with other text

Posted on 2004-09-20
5
Medium Priority
?
34,366 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
[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
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 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

764 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