Click to See Complete Forum and Search --> : this must be figured out!


hungrydino
02-23-2003, 02:49 AM
I want the user to enter a selection of text into a multiline text box. When the 'submit' button is pressed I want the selection of text to be searched for say the word 'cat' - and each instance of this word would be changed into the word 'lion. I can do that right? Because I need to...

Here's some code to help show what I'm trying to do:

<script>
function runfunction () {
var thestring = self.test.box.value; // this would capture the selection of text from the textbox and store it in the variable thestring.

//here's the code that's missing, what can I put here?

var theresult // this variable would be the selection of text after each instance of the word was changed.


self.test.box2.value = theresult // the new text would be displayed in a second multiline textbox

}
</script>


Thanks,
Stephen

Timbuck2
02-23-2003, 04:25 AM
Give this a whirl my friend.


var f = new String()
f="ppplllllllllllll"
f=f.replace("ppp","lll")
alert (f)

Charles
02-23-2003, 06:38 AM
And you would do well to read up on the String.replace() method. See http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm#1194258.

Timbuck2
02-23-2003, 08:05 AM
I think you would have a horrible time with that link. It refers to regular expressions without explaining them very well.
Once you've tried the above code and have it working in your page we can test it and go over some basics if you need it.

hungrydino
02-23-2003, 01:59 PM
thanks guys

Timbuck2
02-23-2003, 07:56 PM
Your welcome,
Charles is correct though. Your not exactly done, most likely, unless thats all you wanted to happen.