vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   RegExp.replace Not Working (https://vborg.vbsupport.ru/showthread.php?t=106602)

SamirDarji 01-29-2006 04:02 AM

RegExp.replace Not Working
 
I'm using the following function to modify tags used for mouseover text:
Code:

function delHoverX()
{
  re = /(\bdsc00001\b)/i;

  imgTags = document.getElementsByTagName("img");
  for (i=0; i<imgTags.length; i++)
  {
    if (re.test(imgTags[i].title))
    {
      origTitle = imgTags[i].title;
      origAlt = imgTags[i].alt;
      imgTags[i].title.replace(re, "$1");
      imgTags[i].alt.replace(re, "$1");
      if (origTitle == imgTags[i].title && origAlt == imgTags[i].alt)
        {
        imgTags[i].title = "same";
        imgTags[i].alt = "same";
        }
    }
    else
    {
      imgTags[i].title = "";
      imgTags[i].alt = "";
    }
  }
}

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.

filburt1 01-29-2006 04:18 AM

If that is a vBulletin-powered page, it will be easier and cleaner to replace in the HTML output before it's even sent to the browser. Do this via a hook in global_complete (IIRC) on the $output variable.

SamirDarji 01-29-2006 06:36 AM

Unfortunately, this isn't a vb page. :( I don't have almost any control on anything. This was code that was given to me that should work and I've narrowed it down to one test case (dsc00001) just to get it working.

It seems like the .replace isn't working for some reason. In spite of the fact that the re.test works dropping it inside the if.

I've looked at the RegExp documentation for Javascript on devguru as well as other sites. I've looked at examples. Seems like everything is written correctly, but it is still not working. I'm simply dumbfounded. If this was in C, I'd step through the whole thing line-by-line while watching every single variable. But I don't have any tools to do that here. :(

Any ideas?

Marco van Herwaarden 01-29-2006 08:59 AM

Turn on displaying all JavaScript errors in your browser. This might give you a clue.

SamirDarji 01-29-2006 02:53 PM

I will try that. Good idea!

Results--no errors related to that code. (There's one error that's there because of a call to a vb object leftover from a cut-and-paste of some vb generated html.)

Any other ideas? I'm playing with using .match now with some better results, but still unusual things are happenning. :(

filburt1 01-29-2006 03:28 PM

Are you trying to create a title attribute for each image that already has an alt tag?

SamirDarji 03-07-2006 03:24 AM

That's exactly what I was trying to do. I don't understand why I never got the email from vb.org of your response. :( Thank you for your help!


All times are GMT. The time now is 08:46 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01431 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete