Script to hide a section if there's no value

Hello,
I have a table that shows discount and amount of rental days (if any).
discount_granted.PNGWhen no discount is granted, and / or no rental days, it shows 0.00 .
no_discount_no_days_to_rent.PNGif all cells are at 0.00 like in the print capoture above, I would like to hide the columns of my table where no discount is granted and / or there's no rental days.
I would need a script that can do that.
here is my html code.
    <TABLE class="FixedSizeTableColumns sized-text">
                      <TBODY>
                        <TR>
                          <TH class="containerSmallExtended">
                            <SPAN class="TitleFirstColumn">Description</SPAN>
                          </TH>
                          <TH class="TotalDiscount TextCenter">Days to Rent</TH>
                          <TH class="TotalDiscount TextCenter">Discount %</TH>
                          <TH class="TextCenter">Qty</TH>
                          <TH class="TextCenter">UOM</TH>
                          <TH class="TextCenter">Unit Price</TH>
                          <TH class="TextCenter">Extended Price</TH>
                        </tr>
                      </TBODY>
                    </TABLE>
                  </TD>
                </TR>{{#childtable.title.rows}}
				<table class="pdfblocktable sized-text">
				<TR>
                  <TD>
                    <SPAN class="TitleField">{{fields.user_def2}}</SPAN>
                  </TD>
                  <!--Title-->
                </TR>
                <TR>
                  <TD class="NoRightPadding">
                    <!--Sub Title Table Start-->
                    <table class="InfoTable sized-text">
                      {{#childtable.subtitle.rows}}
                      <TBODY class="sized-text">
                        <TR>
                          <TD>
                            <SPAN class="SubTitleField">{{fields.user_def3}}</SPAN>
                          </TD>
                        </TR>
                        <TR>
                          <TD class="NoRightPadding">
                            <!--Part Table Start-->
                            <TABLE class="DetailTable FixedSizeTableColumns">
                              {{#childtable.part_usage.rows}}
                              <TBODY class="sized-text">
                                <TR>
                                  <TD class="containerSmallExtended">
                                    <SPAN>{{fields.user_def1}}</SPAN>
                                  </TD>
                                  <TD class="TotalDiscount TextRight"><SCRIPT>FormatDecimal({{fields.user_def_num3}})</SCRIPT></TD>
                                  <TD class="TotalDiscount TextRight"><SCRIPT>FormatDecimal({{fields.price_adj_pct}})</SCRIPT></TD>
                                  <TD class="TextRight"><SCRIPT>FormatDecimal({{fields.user_def_num1}})</SCRIPT></TD>
                                  <TD>{{fields.u_m_out}}</TD>
                                  <TD class="TextRight">
                                    <SCRIPT>FormatDecimal({{fields.bill_price}})</SCRIPT>
                                  </TD>
                                  <TD class="TextRight">
                                    <SCRIPT>FormatDecimal({{fields.ext_price}})</SCRIPT>
                                  </TD>
                                </TR>{{/childtable.part_usage.rows}}
                              </TBODY>
                            </TABLE>

Open in new window

Thank you.
Alain BensimonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
What have you so far?

Each cell (TD) requires an appropriate class. Then you can control the visibility of them.
0
Alain BensimonAuthor Commented:
these are the rows taht I'm working on
<TH class="TotalDiscount TextCenter">Days to Rent</TH>
<TH class="TotalDiscount TextCenter">Discount %</TH>
gives me the tiltes of the columns
and
<TD class="TotalDiscount TextRight"><SCRIPT>FormatDecimal({{fields.user_def_num3}})</SCRIPT></TD>
<TD class="TotalDiscount TextRight"><SCRIPT>FormatDecimal({{fields.price_adj_pct}})</SCRIPT></TD>
gives me the amounts if any.
I've been trying many things to try to hide them, but with no results.
0
ste5anSenior DeveloperCommented:
E.g.

<!DOCTYPE html>
<html>
  <head>
    <script>
      function toggleVisibility() {
        var elements = document.getElementsByClassName("column");
        for (i = 0; i < elements.length; i++) {     
          elements[i].style.visibility = 
            (elements[i].style.visibility !== "hidden" ? "hidden" : "visible");
        }
      }
    </script>
  </head>
  <body>
    <table>
      <thead>
        <tr><th>C1</th><th class="column">C2</th><th>C3</th><tr>
      </thead>
      <tbody>
        <tr><td>R1</td><td class="column">R2</td><td>R3</td><tr>
        <tr><td>R4</td><td class="column">R5</td><td>R6</td><tr>
      </tbody>
    </table>
    <button onclick="toggleVisibility();">Click me!</button>
  </body>
</html>

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Alain BensimonAuthor Commented:
I'm not sure that it applies to my code.
i can't have a button.
It needs to hide the elements with that class if there's no value.
0
ste5anSenior DeveloperCommented:
You're kídding, aren't you?
0
Alain BensimonAuthor Commented:
What do you mean?
0
ste5anSenior DeveloperCommented:
I would need a script that can do that.
Got one, embedded in a complete and concise example.

It needs to hide the elements with that class if there's no value.
You need to determine this in your controller.
0
Alain BensimonAuthor Commented:
I found another way to make it work.
By the way, I'm a beginner in javascript, so it was too difficult for me to adapt your example to my code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alain BensimonAuthor Commented:
The solution provided was too general and I could not adapt it to my code. The contributor took also a lot of time to answer the questions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.