This is a discussion on "JS replace help" within the JavaScript Forum section. This forum, and the thread "JS replace help are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
JS replace help
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
JS replace help
Hello friends,
I want to use replace function in javascript but the client wants that a particular word should be replaced a specified number of times. For example... In a particular page, I want to replace first 5 occurances of the word 'Telecom' to 'Telecommunications'. No matter how many times this word is used in the specified page. Please help |
|
|
|
||||
|
Re: JS replace help
Ah? server-side is best for that kind-of stuff. Don't force javascript to do a recursive look though an unlimited amount of controls. Unless you have one specific control, this is not a good idea!
Here's a good script.
Added /Telecom/g instead of "telecom", so you replace ALL of the word.
Last Blog Entry: Planning Ahead (Yesterday)
Last edited by TheSealPortalTeam; Dec 5th, 2007 at 18:18. Reason: I added regular expressions. |
|
|||
|
Re: JS replace help
Quote:
thanks friend... but, I need that only... replace a speficific number of occurrances... please help |
|
||||
|
Re: JS replace help
I think it would be better to have this guy change the text himself
You can acheive this in a fairly uneconomical way using
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: JS replace help
Quote:
Thanks a lot dear... it works great... but it is not replacing the very first instance of the word business... it is replacing after that... Please, I am not very much familiar with regex... thats why... thanks again... |
|
||||
|
Re: JS replace help
Update the the regex line with
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: JS replace help
Thanks a lot friend... it works now...
really appreciate your help... |
|
||||
|
Re: JS replace help
No problems.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: [SOLVED] JS replace help
hi Rakuli...
1 more favour please bodytext = bodytext.replace(/[\s]?(business)[\s]{1}/i, " <a href='a'>business</a> "); here I want to use a variable instead of the word business both the sides... say the variable is var keyword2Replace = "business"; How will we do that??? Thanks in advance... |
|
||||
|
Re: [SOLVED] JS replace help
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
||||
|
Re: [SOLVED] JS replace help
Well glad to see it's solved!
Last Blog Entry: Planning Ahead (Yesterday)
|
|
|||
|
Re: [SOLVED] JS replace help
It's not working after I changed the code you suggested... big problem for me... variables in regular expression... |
|
||||
|
Re: [SOLVED] JS replace help
You have you to set it up a bit differently to use a variable.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: JS replace help
Please check Rakuli...
http://www.ukloancentral.co.uk/con_adds/check/test.htm It's still not working... |
|
||||
|
Re: JS replace help
Put this
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: JS replace help
Hi Rakuli,
I have done this... but it is still not working... this time I have removed the prompt and specified to replace 5 occurances... http://www.ukloancentral.co.uk/con_adds/check/test.htm Please see this... |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replace <iframe> for PHP | delusion | PHP Forum | 2 | Jun 20th, 2007 14:51 |
| Using RQ Search and Replace for HTML tag editing | diakin | Scripts and Online Services | 0 | Feb 10th, 2007 09:13 |
| Text replace in a table cell on same page | gribble | Web Page Design | 10 | Sep 28th, 2005 05:32 |