Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #4
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I'd try:

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

  • #6
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72 W. 48' 57" , 41 N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #7
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #8
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts

    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...

  • #9
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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...





  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •