+ Reply to Thread
Results 1 to 2 of 2

Thread: Javascript problem

  1. #1
    ph3n0m's Avatar
    ph3n0m is offline Webmonkey ph3n0m will become famous soon enough
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    317
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript problem

    Hi all

    Basically I am trying to create a "word replacer" in javascript

    I have a string (varying piece of text, X amount of characters long.

    I also have a comma seperated array that I have split - my main problem is that I cannot figure out the best way to do a find and replace, matching any of the words in my array to anything in the text string I have.

    Anyone have any ideas - or even a working model of what I am looking for?
    Information for Unmarried Parents | blog | bash.org
    I gotta gotta get away, get away from the human race
    I don't know what I'll see, don't even know what I'll find
    I don't know what to pack, never been to a trip at the mind

  2. #2
    ph3n0m's Avatar
    ph3n0m is offline Webmonkey ph3n0m will become famous soon enough
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    317
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well I got this sorted from through a good friend in Canada

    The solution was relatively simple

    Code:
    <script type="text/javascript">
    var longstring = "comma seperate list of words";
    var brokenstring = longstring.split(",");
    var string = "text to be parsed";
    	for (i=0;i<brokenstring.length;i++){
    	var newString = string.replace(/brokenstring[i]/gi,"<b>"+brokenstring[i]+"</b>");
    	}
    	document.write(newString);
    </script>
    
    Information for Unmarried Parents | blog | bash.org
    I gotta gotta get away, get away from the human race
    I don't know what I'll see, don't even know what I'll find
    I don't know what to pack, never been to a trip at the mind

+ Reply to Thread

Similar Threads

  1. javascript
    By 7aken in forum Coding Help
    Replies: 1
    Last Post: 03-04-2007, 03:50 PM
  2. javascript help
    By 7aken in forum Coding Help
    Replies: 2
    Last Post: 20-02-2007, 06:09 AM
  3. Javascript menu bug?
    By ButtermilkJack in forum Coding Help
    Replies: 1
    Last Post: 15-01-2007, 03:21 PM
  4. Javascript Captcha for use on forms
    By louie in forum Coding Help
    Replies: 8
    Last Post: 23-10-2006, 09:22 AM
  5. Javascript Menu Help (again...)?
    By ButtermilkJack in forum Coding Help
    Replies: 18
    Last Post: 25-04-2006, 12:32 PM

Visitors found this page by searching for:

Nobody landed on this page from a search engine, yet!
SEO Blog

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO

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 58 59 60 61 62 63 64