/    Sign up×
Community /Pin to ProfileBookmark

this must be figured out!

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Timbuck2Feb 23.2003 — Give this a whirl my friend.


var f = new String()

f="ppplllllllllllll"

f=f.replace("ppp","lll")

alert (f)
Copy linkTweet thisAlerts:
@CharlesFeb 23.2003 — [font=georgia]And you would do well to read up on the [font=monospace]String.replace()[/font] method. See http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm#1194258.[/font]
Copy linkTweet thisAlerts:
@Timbuck2Feb 23.2003 — 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.
Copy linkTweet thisAlerts:
@hungrydinoauthorFeb 23.2003 — thanks guys
Copy linkTweet thisAlerts:
@Timbuck2Feb 24.2003 — Your welcome,

Charles is correct though. Your not exactly done, most likely, unless thats all you wanted to happen.
×

Success!

Help @hungrydino spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...