Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > show me how to replace all instances of word in textbox

Reply
Thread Tools

show me how to replace all instances of word in textbox

 
 
alxasa@gmail.com
Guest
Posts: n/a
 
      12-03-2006

Jeff North wrote:
> On 2 Dec 2006 14:43:13 -0800, in comp.lang.javascript
> < om> wrote:
>
> >| I am sorry I moved too fast... I now do understand / /gi tags around
> >| apple. If apples was a var reference to a parent frame, like
> >| 'parent.somestring' instead of just putting a word in there, how would
> >| that work? Thank you so much for your assistance. Have a great
> >| day!
> >|
> >| re = /(parent.somestring)/gi ?

>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <title>Untitled Document</title>
> <script type="text/javascript">
> function ReplaceApples()
> {
> var id, re, inp, str, newstr, wFrm, wTo;
> //--- get text from the input box
> wFrm = document.getElementById("wrdFrom").value;
> wTo = document.getElementById("wrdTo").value;
>
> //--- make new regexp
> re = new RegExp(wFrm,"gi");
> id = document.getElementById("sunny");
> str = id.value;
> newstr=str.replace(re, wTo);
> id.value = newstr;
> }
> function ResetChange()
> {
> document.getElementById("sunny").value="Apples are round, and apples
> are juicy.";
> }
> </script>
> </head>
> <body>
> <textarea id="sunny" cols=25>Apples are round, and apples are
> juicy.</textarea>
> <br />
> <br />
> Word from
> <input name="wrdFrom" type="text" id="wrdFrom" value="" />
> <br />
> Word to
> <input name="wrdTo" type="text" id="wrdTo" />
> <br />
> <input name="btn" type="button" onclick="ReplaceApples()"
> value="Change" />
> <input type="button" name="Button" value="Reset"
> onclick="ResetChange()"/>
> </body>
> </html>
> ---------------------------------------------------------------
> : Remove your pants to reply
> ---------------------------------------------------------------


Thank you Jeff, and all so much Have a nice day.

 
Reply With Quote
 
 
 
 
mick white
Guest
Posts: n/a
 
      12-03-2006
wrote:

> I am sorry I moved too fast... I now do understand / /gi tags around
> apple. If apples was a var reference to a parent frame, like
> 'parent.somestring' instead of just putting a word in there, how would
> that work? Thank you so much for your assistance. Have a great
> day!
>
> re = /(parent.somestring)/gi ?
>

re = new RegEx(parent.somestring,"gi")

or

re= eval("/"+parent.somestring+"/gi")

Mick
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-08-2006
mick white wrote:

> wrote:
>> re = /(parent.somestring)/gi ?
>>

> re = new RegEx(parent.somestring,"gi")


OK.

> or
>
> re= eval("/"+parent.somestring+"/gi")


Nonsense.


PointedEars
 
Reply With Quote
 
mick white
Guest
Posts: n/a
 
      12-09-2006
Thomas 'PointedEars' Lahn wrote:

> mick white wrote:


>> re = new RegEx(parent.somestring,"gi")

>
>
> OK.
>
>
>>or
>>
>>re= eval("/"+parent.somestring+"/gi")

>
>
> Nonsense.


Not the best, perhaps, but "Nonsense"? No.
Mick

 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      12-09-2006
mick white wrote on 09 dec 2006 in comp.lang.javascript:
> Thomas 'PointedEars' Lahn wrote:
>> mick white wrote:

>
>>> re = new RegEx(parent.somestring,"gi")

>> OK.
>>
>>>or
>>>re= eval("/"+parent.somestring+"/gi")

>>
>> Nonsense.

>
> Not the best, perhaps, but "Nonsense"? No.


Good of you to wash some ears, Mick, but eval() is evil.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-09-2006
mick white wrote:

> Thomas 'PointedEars' Lahn wrote:
>> mick white wrote:
>>> re = new RegEx(parent.somestring,"gi")

^
>>
>> OK.


That was premature. The constructor is RegExp().

>>> or
>>>
>>> re= eval("/"+parent.somestring+"/gi")

>>
>>
>> Nonsense.

>
> Not the best, perhaps, but "Nonsense"? No.


If you do not consider it nonsense, then you have to deal with this
question:

What does this accomplish more that cannot be done better with calling the
constructor function?


PointedEars
--
Indiana Jones: The Name of God. Jehovah.
Professor Henry Jones: But in the Latin alphabet,
"Jehovah" begins with an "I".
Indiana Jones: J-...
 
Reply With Quote
 
mick white
Guest
Posts: n/a
 
      12-09-2006
Thomas 'PointedEars' Lahn wrote:

> mick white wrote:
>
>
>>Thomas 'PointedEars' Lahn wrote:
>>
>>>mick white wrote:
>>>
>>>> re = new RegEx(parent.somestring,"gi")

>
> ^
>
>>>OK.

>
>
> That was premature. The constructor is RegExp().


Ahh, the missing "p", good catch.
>
>
>>>>or
>>>>
>>>>re= eval("/"+parent.somestring+"/gi")
>>>
>>>
>>>Nonsense.

>>
>>Not the best, perhaps, but "Nonsense"? No.

>
>
> If you do not consider it nonsense, then you have to deal with this
> question:
>
> What does this accomplish more that cannot be done better with calling the
> constructor function?


It handles control characters, "\n", "\t" etc..., a little better.
Mick

>
>
> PointedEars

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-09-2006
mick white wrote:

> Thomas 'PointedEars' Lahn wrote:
>> mick white wrote:
>>>Thomas 'PointedEars' Lahn wrote:
>>>>mick white wrote:
>>>>>re= eval("/"+parent.somestring+"/gi")
>>>>Nonsense.
>>>Not the best, perhaps, but "Nonsense"? No.

>>
>> If you do not consider it nonsense, then you have to deal with this
>> question:
>>
>> What does this accomplish more that cannot be done better with calling
>> the constructor function?

>
> It handles control characters, "\n", "\t" etc..., a little better.


In what way, please?


PointedEars
--
The English government is much of a German poodle as
other governments. The Germans infiltrated them all.
-- "The only real Barbara Schwarz", dsw.scientology,
< >)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
replace instances of text on page with image or other text? juglesh Javascript 16 12-27-2004 04:14 AM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM
Replace every n instances of a string Tom Cross Python 1 08-15-2003 11:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57