Diego Cespedes
Diego Cespedes

Reputation: 1353

Laravel 5.1 - Hide section if variable has a value (javascript)

i'm working with laravel 5.1 (ecommerce), i passed some variables to my view:

My variable "$price_coupon" con be "0" OR ">0" for example 10,20 etc...

I would like HIDE this:

<tr class="cart-subtotal" id="coupon">
<th>Coupon:</th>
<td>
<span class="amount">€{{ number_format($price_coupon, 2) }}</span>
</td>
</tr>

IF $price_coupon = 0 AND show IF $price_coupon > 0.

I think that this is feature for javascript right? how can do it? Thank you for your help!

This is all the table of my view: order-detail.php

<table>
        <tbody>
           <tr class="cart-subtotal">
            <th>Subtotale:</th>
                <td><span class="amount">€{{ number_format($total, 2) }}</span></td>
                </tr>

                <tr class="cart-subtotal" id="coupon">
                <th>Coupon:</th>
                <td><span class="amount">€{{ number_format($price_coupon, 2) }}</span></td>
                </tr>

                <tr class="shipping">
                <th>shipping:</th>
                <td>€<input type="text" id="price_ship" name="price_ship" class="price_ship" disabled /></td>
                </tr>

                <tr class="order-total">
                <th>Totale Ordine:</th>
                <td><strong><span class="amount">
                €<input type="text" id="total_ship" name="total_ship" class="total_ship" disabled />

              </span></strong> </td>
        </tr>
</tbody>
</table>

i corrected this question: I'm using also blade template.

Upvotes: 0

Views: 717

Answers (2)

Diego Cespedes
Diego Cespedes

Reputation: 1353

Hi i fix this with blade, like this:

@if($price_coupon >0)
    <tr class="cart-subtotal">
        <th>Sconto:</th>
        <td><span class="amount">€{{ number_format($price_coupon, 2) }}</span></td>
    </tr>
@endif

Upvotes: 1

ArtisticPhoenix
ArtisticPhoenix

Reputation: 21661

in javascript ( jQuery )

 if( parseInt( $('.amount').text() ) <= 0 ){
      $('.amount').closest('tr').css('display', 'none');
 }else{
     $('.amount').closest('tr').css('display', '');
 }

You could also use

 parseFloat()

as it is currency and has decimal values. But that would only matter for values like 0.4 or less because of rounding.

What's this weird thingy bob pounds? We just use $ on my side of the pond. Makes me wonder do they do this for jQuery €('.class') and this for php €var; hmm...

I actually have an English friend, to make a long story short he was back in the 'old' world visiting his family and said he got a 100 pound phone. I said to him, wow that's heavy lol.

Upvotes: 1

Related Questions