Script to hide a section

Hello,
I have this row in a table that calculates the value of a potential discount and I gave it a class named "TotalDiscount".
<TR class="TotalDiscount">
                      <TH style="width:80%" class="SummaryLine">Total Discount Offered</TH>
                      <TD class="TextRight Bold SummaryLine">
                      <SCRIPT><p>FormatDecimal({{fields.total_discount}})</p></SCRIPT>
                       </TD>
 </TR>

Open in new window

If a discount was given, the cell displays the amount, and if no discount was given, it displays "0.00".
I would like to have  a script that hide all sections that have the class "TotalDiscount" if the value is "0.00".

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.

Dorababu MSenior Software EngineerCommented:
if(FormatDecimal({{fields.total_discount}}) > 0 )
{
<TR class="TotalDiscount">
                      <TH style="width:80%" class="SummaryLine">Total Discount Offered</TH>
                      <TD class="TextRight Bold SummaryLine">
                      <SCRIPT><p>FormatDecimal({{fields.total_discount}})</p></SCRIPT>
                       </TD>
 </TR>
}

Open in new window

0
Dorababu MSenior Software EngineerCommented:
If you are working with angular then you can use below

<TR class="TotalDiscount" ng-if="FormatDecimal({{fields.total_discount}}) > 0">
                      <TH style="width:80%" class="SummaryLine">Total Discount Offered</TH>
                      <TD class="TextRight Bold SummaryLine">
                      <SCRIPT><p>FormatDecimal({{fields.total_discount}})</p></SCRIPT>
                       </TD>
 </TR>

Open in new window

0
leakim971PluritechnicianCommented:
replace what you posted by the following :
<script>
var total_discount = {{fields.total_discount}};
if(total_discount)
	document.write('<tr class="TotalDiscount">\n\t\t<th style="width:80%" class="SummaryLine">Total Discount Offered</th>\n\t\t<td class="TextRight Bold SummaryLine"><p>' + total_discount.toFixed(2) + '</p></td></tr>');
</script>

Open in new window

1

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Alain BensimonAuthor Commented:
This solution worked awesome. Thank you so much.
0
leakim971PluritechnicianCommented:
what is your server side language/framework ?
0
Alain BensimonAuthor Commented:
Actually, it is not really a server. I'm working on reports that are fetching data from a database and the layout is made in html.
0
leakim971PluritechnicianCommented:
ok got it
0
Alain BensimonAuthor Commented:
But your solution was perfect for me :).
0
Alain BensimonAuthor Commented:
ok, so I'm trying to reproduce it for the columns who calculate it, but it's a little bit more tricky.
I have these 2 columns titles

<TH class="TotalDiscount TextCenter">Days to Rent</TH>
<TH class="TotalDiscount TextCenter">Discount %</TH>

and the data
<TD class="TotalDiscount TextRight"><SCRIPT>FormatDecimal({{fields.user_def_num3}})</SCRIPT></TD>
<TD class="TotalDiscount TextRight"><SCRIPT>FormatDecimal({{fields.price_adj_pct}})</SCRIPT></TD>

this represent the columns "days to rent" and "Discount%" that are showed on the print captures I have attached.

I would also like a script to have the columns be hidden if there's "0.00" which means no discount at all has been granted or no days to rent at all.
Ofcourse, if only one of the cell contains an amount different than "0.00", the whole column should display.
Thank you.
with-a-discount.PNG
with-no-discount.PNG
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.