Hi, can someone please show me how to most elegently do this?.....
I have a textbox, and I want to search the contents of it and replace
all instances of a certain word, and replace that word with something
else. For the purposes of this it could be replacing "green" with
"blue". Can someone please show me how to properly do this? :)
Sincerest regards, Alxasa.
Dec 1 '06
17 8135
Jeff North wrote:
On 2 Dec 2006 14:43:13 -0800, in comp.lang.javas cript al****@gmail.co m
<11************ *********@73g20 00cwn.googlegro ups.comwrote:
| 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.somestr ing' 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.somestr ing)/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>Untitl ed Document</title>
<script type="text/javascript">
function ReplaceApples()
{
var id, re, inp, str, newstr, wFrm, wTo;
//--- get text from the input box
wFrm = document.getEle mentById("wrdFr om").value;
wTo = document.getEle mentById("wrdTo ").value;
//--- make new regexp
re = new RegExp(wFrm,"gi ");
id = document.getEle mentById("sunny ");
str = id.value;
newstr=str.repl ace(re, wTo);
id.value = newstr;
}
function ResetChange()
{
document.getEle mentById("sunny ").value="Apple s 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="Replac eApples()"
value="Change" />
<input type="button" name="Button" value="Reset"
onclick="ResetC hange()"/>
</body>
</html>
--------------------------------------------------------------- jn******@yourpa ntsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Thank you Jeff, and all so much :) Have a nice day. al****@gmail.co m 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.somestr ing' 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.somestr ing)/gi ?
re = new RegEx(parent.so mestring,"gi")
or
re= eval("/"+parent.somest ring+"/gi")
Mick
mick white wrote: al****@gmail.co m wrote:
>re = /(parent.somestr ing)/gi ?
re = new RegEx(parent.so mestring,"gi")
OK.
or
re= eval("/"+parent.somest ring+"/gi")
Nonsense.
PointedEars
Thomas 'PointedEars' Lahn wrote:
mick white wrote:
> re = new RegEx(parent.so mestring,"gi")
OK.
>>or
re= eval("/"+parent.somest ring+"/gi")
Nonsense.
Not the best, perhaps, but "Nonsense"? No.
Mick
mick white wrote on 09 dec 2006 in comp.lang.javas cript:
Thomas 'PointedEars' Lahn wrote:
>mick white wrote:
>> re = new RegEx(parent.so mestring,"gi")
OK.
>>>or re= eval("/"+parent.somest ring+"/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)
mick white wrote:
Thomas 'PointedEars' Lahn wrote:
>mick white wrote:
>> re = new RegEx(parent.so mestring,"gi")
^
>> OK.
That was premature. The constructor is RegExp().
>>or
re= eval("/"+parent.somest ring+"/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-...
Thomas 'PointedEars' Lahn wrote:
mick white wrote:
>>Thomas 'PointedEars' Lahn wrote:
>>>mick white wrote:
re = new RegEx(parent.so mestring,"gi")
^
>>>OK.
That was premature. The constructor is RegExp().
Ahh, the missing "p", good catch.
>
>>>>or
re= eval("/"+parent.somest ring+"/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
mick white wrote:
Thomas 'PointedEars' Lahn wrote:
>mick white wrote:
>>>Thomas 'PointedEars' Lahn wrote: mick white wrote: >re= eval("/"+parent.somest ring+"/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 ,
<16************ **************@ posting.google. com>) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: oLE |
last post by:
I would like to add some javascript to show/hide a certain row of a
table. The first row of the table contain the hyperlink that calls the
javascript the second row is the one i want to show/hide with the
javascript in a toggle fashion.
the problem is a know very little javascript and have become incredibly
frustrated because i went ahead thinking it was going to be like C. its not.
I know i can use these lines to do the actual work:
|
by: juglesh |
last post by:
Hello,
I need to look through the text on a page and replace certain words with an
image or other word
something like:
read document
find all instances of the word "blah"
change all instances of the word "blah" to <img src="MyPicture.jpg" >
|
by: gregpinero |
last post by:
I'm trying to write a little script that will have a list of word pairs
which will loop through that list and replace all instances of each
word with the other word.
I'm very new to javascript so I'm not quite sure where to get started.
Here is my python "prototype" in case you want a better idea of what
I'm trying to do:
<code>
corpus="""
|
by: Tomomichi Amano |
last post by:
Could some one tell me how I can seach and replace only one word in a
textBox (THE FIRST WORD THAT COMES AFTER THE CURSOR). I already know how to
replace ALL , but I don't know how to REPLACE one, and how to SEARCH one and
select that point.
Thank in advance
|
by: Tomomichi Amano |
last post by:
Hello.
I want to make replace & search functions in my text editor. Thanks to the
kind people here at the newsgroup, I was able to make the
function.
But I was not able to understand how to REPLACE the next word (the nearest
word from the cursor; not REPLACE ALL, but replace only one word) and SEARCH
the next word.
COuld some one help me? Thanks in advance.
| |
by: Ramsin Savra |
last post by:
Hi,
What do you suggest to do if I want to do a search in TextBox ? I know that
using RichTextBox, we could have Find method to search for a specific word
or information but I was wonder if somebody knows some methods for Find and
Replace in TextBox.
Thanks
|
by: ed |
last post by:
Hi I can't seem to make the Me.Show() work
My code is
dim dlgresult as dialogresul
dlgresult=me.show(
The message is : "expression does not produce a value
|
by: gar |
last post by:
Hi,
I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code
text= Replace(text, """", "'"
This works fine (for normal double quotes).The problem comes in when you copy a double quote from MS Word and paste it in the text box. What happens is the double quote becomes slanted (“) so my code above can't filter it. I tried to do this
text= Replace(text, "““","'")
|
by: gregpinero |
last post by:
Hi guys,
What I'm trying to do is find all instances of an acronymn such as IBM
on a webpage and replace it with <acronym title="International Business
Machines">IBM</acronym>. However in my code below it replace the <,
and > with < and >.
Thus it replaces IBM with:
<acronym title="International Business
Machines">IBM</acronym>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |