Click to See Complete Forum and Search --> : Text Replacing


Zero
04-11-2003, 05:38 PM
Let's say you don't have the ability to set a certain bit of text the way you want it...is there a way to change this text to another bit of text that you specify, using JavaScript?:confused:

Zero
04-11-2003, 06:48 PM
I want to exchange some text...for somemore text...? What's to guess?

Zero
04-11-2003, 06:51 PM
I want to exchange some text...for somemore text...? What's to guess?

Sorry, clicked the wrong button...delete that other thread...

Jona
04-11-2003, 06:53 PM
Let's see..

var str = "Some Text of Yours."
str=str.replace("T", "N");

Or...

var str = "Some Text of Yours."
str=str.replace(/T/, "N");

Or...

var str = "Some Text of Yours."
str=str.split("T").join("N");

The method depends on what you're after. That's what Dave meant.

khaki
04-11-2003, 07:00 PM
or you guess that's what me meant! :rolleyes:
LOL
;) k

Zero
04-11-2003, 09:52 PM
I want to replace the word 'Zero' with an HTML IMG tag...can you guess off of that?;)

Jona
04-11-2003, 09:55 PM
Oh, put it in a <div> and use innerHTML.

Zero
04-11-2003, 10:47 PM
Originally posted by Jona
Oh, put it in a <div> and use innerHTML.

Run that by me, again?:confused:

Jona
04-11-2003, 10:51 PM
Erhem, put it in a <div> and user innerHTML. :p

Okay, on a serious note. Something like this:

<html><head>
<script>
function ok(){
imgObj.innerHTML="Zero";
}
</script>
</head><body>
<div id="imgObj"><img src="file.jpg"></div><br>
<input type=button value="Okay..." onClick="ok()">
</body></html>

Zero
04-13-2003, 01:12 PM
Ahh...I see. Thanks.:D

Zero
04-13-2003, 01:21 PM
Wait...I want to change the word 'Zero' to the image...and, it doesn't seem to work multiple times on the same page...:confused: Is there an alternative method?

Jona
04-14-2003, 11:46 PM
Okay, do this:

<html><head>
<script>
function ok(){
imgObj.innerHTML="<img src="file.jpg">";
}
</script>
</head><body>
<div id="imgObj">Zero</div><br>
<input type=button value="Okay..." onClick="ok()">
</body></html>

Zero
04-15-2003, 12:59 PM
Nope...still didn't work the way I want it to...please tell me there's an alternative method...and, I'd like to have one that occurs on page load, not when you click a button. :confused:

Jona
04-15-2003, 01:04 PM
Change this:

</head><body>
<div id="imgObj">Zero</div><br>
<input type=button value="Okay..." onClick="ok()">
</body></html>

To this:

</head><body onload="ok()">
<div id="imgObj">Zero</div><br>
</body></html>

Zero
04-15-2003, 01:05 PM
I know, I tried that...I'm not a complete JS idiot...but, the script isn't working the way I want it to...:(

Jona
04-15-2003, 01:06 PM
Then I'm not understanding what, "the way you want it to" is.

Zero
04-15-2003, 01:09 PM
I want to change 'Zero' to ' http://invisionfree.com:54/4/29/pip/adminname.gif ' ...and, your script isn't changing it...

EDIT: Any particular reason of why the IMG tags aren't working?