简体   繁体   中英

Add class to input field if the field has a value

Thanks in advance!

Please could someone help me I need to add a class ".filled" to the input field below if the value field isn't null?

<input name="total_price" class="form-control" id="ProposalPriceTotal" type="text" value="{{ $proposal->total_price }}">

Full Code: https://codepen.io/FluxedDigital/pen/vvJzgX

Thanks!

You can easily do that with PHP ternary operator. You can Google it later for explanation. It just a simple code:

<input name="total_price" class="form-control {{ $proposal->total_price 
== null ? '' : 'filled' }}" id="ProposalPriceTotal" type="text" value=" 
{{ $proposal->total_price }}">

Surely, the comparison value is depend on your type of data. But I think that using null should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM