3 Replies Latest reply: Jan 13, 2014 10:54 AM by ptsdcg RSS

    Javascript help

    ptsdcg

      Hi,

       

      I need some help with javascript.   I have a dynamic action similar to below, but instead of testing a 1 byte string, I want to test a substring.   So, if C1 = '111111', and I want to test check the first character (ie.  '1'), how would I specify that?

       

      Thanks.

      Paul

       

       

      $("td[headers='C1']").each(function(){
         switch($(this).text())
         {
              case "1":
                 $(this).parent().children("td[headers='FC_QTY_MONTH01']").css({"background-color":"#FFFF99"});
                 break;
              default:
                 break;
          }
          $(this).css({"visibility":"hidden"});
          $("th[id='C1']").css({"visibility":"hidden"});
      });
      
        • 1. Re: Javascript help
          jariola

          Hi,

           

          Try use JavaScript substr method.

          http://www.w3schools.com/jsref/jsref_substr.asp

           

          Try if this works

          $("td[headers='C1']").each(function(){ 
             switch($(this).text().substr(1,1)) 
             { 
                  case "1": 
                     $(this).parent().children("td[headers='FC_QTY_MONTH01']").css({"background-color":"#FFFF99"}); 
                     break; 
                  default: 
                     break; 
              } 
              $(this).css({"visibility":"hidden"}); 
              $("th[id='C1']").css({"visibility":"hidden"}); 
          }); 
          

           

          Regards,

          Jari

          • 2. Re: Javascript help
            ptsdcg

            Jari,

             

            Thanks for the reply.  I am aware of the substr method, but I don't know javascript syntax well enough to know how to format.   Would the substr be part of the switch statement or around the td[headers='C1']   or .... ?

             

            Thanks.

            Paul

            • 3. Re: Javascript help
              ptsdcg

              Jari,

               

              Nevermind my last reply.  I now see you posted the solution (as part of the switch statement).   It's working!   Thanks so much!

               

              This is very useful for highlighting background colors for multiple columns (based on other columns) without them taking up blank space in an interactive report.

               

              Paul