Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't get value of numeric input if input is greater then 0

<input type="number" placeholder="Number of people*" class="user_number" min="1" max="5">
let user_number = document.getElementsByClassName("user_number");
if($(user_number).val() > 0){
            console.log($(user_number).val());
        }

but when i put anything more than 0 console doesn’t show up help please

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can attach an event listener for the "input" event so that the value is checked each time it changes.

$('.user_number').on('input', function() {
  if (this.valueAsNumber > 0) {
    console.log(this.value);
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="number" placeholder="Number of people*" class="user_number" min="1" max="5">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading