Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2006, 04:02 AM
SamirDarji SamirDarji is offline
 
Join Date: Apr 2004
Posts: 645
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 01-29-2006, 04:18 AM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 01-29-2006, 06:36 AM
SamirDarji SamirDarji is offline
 
Join Date: Apr 2004
Posts: 645
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #4  
Old 01-29-2006, 08:59 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Turn on displaying all JavaScript errors in your browser. This might give you a clue.
Reply With Quote
  #5  
Old 01-29-2006, 02:53 PM
SamirDarji SamirDarji is offline
 
Join Date: Apr 2004
Posts: 645
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 01-29-2006, 03:28 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you trying to create a title attribute for each image that already has an alt tag?
Reply With Quote
  #7  
Old 03-07-2006, 03:24 AM
SamirDarji SamirDarji is offline
 
Join Date: Apr 2004
Posts: 645
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:16 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06393 seconds
  • Memory Usage 2,217KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete