How to get an exact match whilst searching inside a string.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Neil Gilbert

    #1

    How to get an exact match whilst searching inside a string.

    Ok i am fudging a legacy CRM system and i need to hide a button on the script using client side javascript.

    I am trying to hide a button on the screen based on the URL containing the word SendEmail by looking inside the HREF tag and if there is a match... hide it!

    The code works fine apart from there is another button with exactly the same markup, etc but the link shows SendEmailUsingO utlook (please see html below).

    So i need to find the exact match of SendEmail and exclude SendEmailUsingO utlook.

    P.S. I can't modify any of the HTML, CSS, etc this is generated by the system.

    i am currently using:

    Code:
    window.attachEvent("onload",hideElement); 
    
    function hideElement() 
    { 
    for(i=0;i<document.all.length;i++) 
    {
    if(document.all[i].tagName=='A') 
    {
    if(document.all[i].href.search(/SubmitEmail/i)>-1) 
    {
    document.all[i].style.visibility = hidden;
    }
    }
    }
    }
    The html buttons as generated from the CRM system:
    Code:
    <A CLASS=ButtonItem HREF="javascript:try{if(SubmitEmail            (true)==true) self.document.EntryForm.submit();}catch(err){alert('The path to local file is incorrect, please use Browse button to select file.')}"><IMG SRC="/CRM/Themes/img/color/Buttons/SendEmail.gif" BORDER=0 ALIGN=MIDDLE></A>
    <A CLASS=ButtonItem HREF="javascript:try{if(SubmitEmailUsingOutlook(true)==true) self.document.EntryForm.submit();}catch(err){alert('The path to local file is incorrect, please use Browse button to select file.')}"><IMG SRC="/CRM/Themes/img/color/Buttons/SendOutlookEmail.gif" BORDER=0 ALIGN=MIDDLE></A></TD>
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    use .indexOf() to search for some characters in a String.

    Ex:
    Code:
      var str = "This is a Search String";
      var ind = str.indexOf("Search");
    the ind will be -1 if the search string is no there. If it is there it will return starting index of the character sequence.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      That wouldn't work as it'd still find the longer string. For a very simple solution, you could look for "SendEmail " (with a space).

      Comment

      Working...