Web Analytics Made Easy -
StatCounter search and replace - CodingForum

Announcement

Collapse
No announcement yet.

search and replace

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • search and replace

    I need a javascript that reloads a page and replaces a string, say a unique div tag or something, and replace it with some other tag.... help.....

  • #2
    i think you have to be a little bit more specific, with exactly what it is that you're looking for, before we can help you. maybe an example?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      Example

      I'm not allowed to touch the cgi script which generates the page to begin with. so I need a javascript function that will look for the string "you are right" and replace it with an image <img src="right.gif"/>

      perhaps using an array since their will be several questions on the page...

      I hope that makes sense.

      Comment


      • #4
        eww. that could be tricky. if the phrase you're looking for isn't stand alone, and inside of some sort of object with an id, like a DIV or SPAN, you're out of luck, with javascript. if it's inside of a DIV, though, i think i can help.
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment


        • #5
          I'd try:

          document.body.innerHTML = document.body.innerHTML.replace(RegExp('you are right','gi'), '<img src="right.gif"/>');
          jasonkarldavis.com

          Comment


          • #6
            nice one.
            bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

            i am a loser geek, crazy with an evil streak,
            yes i do believe there is a violent thing inside of me.

            Comment


            • #7
              reply

              your solution is not cross browser - but thank you. I thinked I found the solution:

              function replace_image(key) {
              if(key == 'you are right'){
              document.write('<img src="yes.gif" alt="<-- you are right!" \/>');
              }else{
              document.write('<img src="no.gif" alt="<-- you are wrong!" \/>');
              }
              }

              </script>
              </head>

              <body>
              <script language="JavaScript">
              replace_image('%answer%')
              </script>
              </body>

              Comment


              • #8
                Re: reply

                Originally posted by drewamnh
                your solution is not cross browser - but thank you. I thinked I found the solution:

                function replace_image(key) {
                if(key == 'you are right'){
                document.write('<img src="yes.gif" alt="<-- you are right!" \/>');
                }else{
                document.write('<img src="no.gif" alt="<-- you are wrong!" \/>');
                }
                }

                </script>
                </head>

                <body>
                <script language="JavaScript">
                replace_image('%answer%')
                </script>
                </body>
                It works in IE4+/NS6+.

                Anyway, is %answer% some ASP variable or something? Otherwise what you just posted won't do anything in a purely client-side setting.

                BTW, next time you have ASP support - let us know.
                Much better solutions are possible...
                jasonkarldavis.com

                Comment


                • #9
                  ASP

                  ahhh....

                  I used to work in a Microsoft world- but now I work at a museum which is all open source freeware uukkk...

                  how I miss the good old asp days...



                  Comment

                  Working...
                  X