Aarivex
Aarivex

Reputation: 1

jQuery - setInterval doesnt work

I'm trying to code a little Homepage with jQuery. It has a form and I want to check something with jQuery.

I have a textbox with the id points. jQuery has following code:

$(document).ready(function() {
  setInterval(function() {
    if ($("#points").value().length > 500) {
      alert("Too many points!");
    }}, 100)
});

But it doesn't work. Can someone help me?

Upvotes: -1

Views: 66

Answers (1)

Weafs.py
Weafs.py

Reputation: 22998

I see two problems:

  1. There is no function called value() in jQuery. It's val(). For JavaScript, It is .value.
  2. You are trying to get the length of the number, which will give you 3 if the number was 123.

    $(document).ready(function() {
      setInterval(function() {
        if ($("#points").val() > 500) {
          alert("Too many points!");
        }
      }, 100);
    });
    

Upvotes: 1

Related Questions