943,929 Members | Top Members by Rank

Ad:
Jan 28th, 2006
0

RegExp.replace Not Working

Expand Post »
I'm using the following function to modify tags used for mouseover text:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function delHoverX()
  2. {
  3. re = /(\bdsc00001\b)/i;
  4.  
  5. imgTags = document.getElementsByTagName("img");
  6. for (i=0; i<imgTags.length; i++)
  7. {
  8. if (re.test(imgTags[i].title))
  9. {
  10. origTitle = imgTags[i].title;
  11. origAlt = imgTags[i].alt;
  12. imgTags[i].title.replace(re, "$1");
  13. imgTags[i].alt.replace(re, "$1");
  14. if (origTitle == imgTags[i].title && origAlt == imgTags[i].alt)
  15. {
  16. imgTags[i].title = "same";
  17. imgTags[i].alt = "same";
  18. }
  19. }
  20. else
  21. {
  22. imgTags[i].title = "";
  23. imgTags[i].alt = "";
  24. }
  25. }
  26. }
It is being used on the following web page: http://huntsvillecarscene.smugmug.com/gallery/1144571

For some reason, the regexp.replace is not working. There is a test clause in there to help me diagnose some of what's going on.

I'm not a Javascript programmer. I only have a limited background in C. I've been working on this for 2 days and am frustrated out of my mind.

Any assistance appreciated.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Samir is offline Offline
20 posts
since Jul 2005
Jan 29th, 2006
0

Re: RegExp.replace Not Working

Anyone?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Samir is offline Offline
20 posts
since Jul 2005
Jan 31st, 2006
0

Re: RegExp.replace Not Working

Regular Expressions have always been very difficult for me, for some reason. I'd be happy to try to help when I have a bit more time later this week.

Can you post a very simple "test harness" version of your HTML here?
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Jan 31st, 2006
0

Re: RegExp.replace Not Working

it should be \i not /i for case insensitive in your re (first line of code) so you are possibly never getting a match. its is easy to miss as some others are / (for example /g for whole string)
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: HELP! With Javascripts Pop-Up Window
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: No toolbars in window





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC