Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
How to show blank instead of 0 in a numeric input element

HTML numeric input in form is defined as

@Html.TextBoxFor(m => Model.Products[i].Soodkogus,
     new { type = "number", min = 0, @class = "quantity" })

This produces input boxes with content 0.

How to make the input box blank if its value is 0? Only non-zero values should shown.

This is an ASP.NET 6 MVC Razor application. jQuery and Bootstrap 5 are used.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't know what your framework is doing in background when generating this input fields, but if you just want to achieve this logic with jQuery - something like this should work.

$(document).ready(function(){
  $('input').val("");
  $('input').on('input',function(){
    if($(this).val() < 1)
    {
      $(this).val("");
    }
  });
});
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<input type="number" min="0">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!