Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide zero values of an empty input(number type)

I have a form that gives me data from database, i have number input type. By default it is "0" showed for empty entries. I want to hide "0" from the field and show the value just if is different of 0.

I tried with the code below but it doesn't work.

 <input data-validate="number"  value="<?php echo $value; ?>" class="form-control" onload="if(this.value  == '0') { this.value = ' '; } " >
like image 936
Patrick Lemark Avatar asked Oct 24 '25 15:10

Patrick Lemark


1 Answers

Add ternary operator to PHP block instead:

<input data-validate="number" value="<?php echo ($value != '0' ? $value : ''); ?>" class="form-control">
like image 60
antyrat Avatar answered Oct 27 '25 04:10

antyrat