Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .change() function doesnt`work on localhost

The following code works on jsfiddle but does not work on localhost, can you help me please?

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <script>
        $('.puankontrol').change(function() {
          var x = $(this).val() * 1;   
          if((x < 1) ||  (x > 5))
          {
              $(this).val(3);
              alert("Please enter value between 1-5!");
          }
        });
    </script>
</head>
<body>

     <form>
      <input class="puankontrol" type="text" name="puan"/><BR>
      <input class="puankontrol" type="text" name="puan"/><BR>
      <input class="puankontrol" type="text" name="puan"/><BR>
    </form>
    <div id="other">
      Trigger the handler
    </div>

</body>
</html>

`

like image 794
sdiri Avatar asked Dec 02 '25 02:12

sdiri


1 Answers

Try

$(document).ready(function(){
   //change function declaration.
});

also use <script type="text/javascript"> for adding script tag.

like image 65
Dipesh Parmar Avatar answered Dec 04 '25 16:12

Dipesh Parmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!