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?
 
leakim971Connect With a Mentor PluritechnicianCommented:
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
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.