RegExp.replace Not Working

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2005
Posts: 19
Reputation: Samir is an unknown quantity at this point 
Solved Threads: 0
Samir Samir is offline Offline
Newbie Poster

RegExp.replace Not Working

 
0
  #1
Jan 28th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 19
Reputation: Samir is an unknown quantity at this point 
Solved Threads: 0
Samir Samir is offline Offline
Newbie Poster

Re: RegExp.replace Not Working

 
0
  #2
Jan 29th, 2006
Anyone?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: RegExp.replace Not Working

 
0
  #3
Jan 31st, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: RegExp.replace Not Working

 
0
  #4
Jan 31st, 2006
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)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 3816 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC