How to check the on change event in multiple elements with same class name in Rails using Jquery

gangothri

in a rails module, when user enters less than 0 value he should get invalid message.

in js file i have written a onchange function which expecting when a textbox gets less than zero value this function should trigger an alert.

$(document).on('onchange',".default-value" (function(event) {
  e.preventDefault();
  e.stopPropagation();
  $('.default-value').each(function(){
     var num = $(this).val();
     if( num < 0)  
      alert("Invalid Entry");
  });
});

in my slim.erb file i have written following code.in here the text box values are to be held and sent for the function i have written inside the js file.

 = y.input :default_value, label: false, input_html: { class: "default-value #{ y.object.parameter.parameterize } " }

I expect an invalid error right when I type less than 0 value.

Kamal Pandey

update with

    $(".default-value").change(function(){
        if($(this).val() < 0) {
         $(this).val('');
         alert("Invalid Entry");

       }
   });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to fire an event on class change using jQuery?

jQuery same click event for multiple elements

How to check multiple elements has same class using jquery?

Check if multiple elements with same class exist

jQuery Check if multiple elements have a class

Binding an event listener to multiple elements with the same class

How to wrap same class elements in list box using jquery?

Event listener on multiple elements with the same class

How to show image on another image on click while there are multiple images with same class name using javascript or jquery?

How do I select multiple elements with the same name using xmlstarlet?

How to toggle multiple elements with same class name on click

Jquery use same event on multiple elements

How do you animate multiple elements with the same class name?

jquery button event on multiple buttons with the same class

How to check change in class name using protractor

How can I apply a character limit to an element that shares a class name with multiple elements using JQuery?

How to select elements using jQuery by partial ID and a class at the same time?

jQuery .change event not firing on multiple same class

Set html contents of an element using jQuery but with multiple elements of the same class

How do I check which radio button is selected when there are multiple radio buttons with the same name? (using jquery)

Same class name for multiple elements but execute event independently in pure jQuery

Jquery - How to select 2 elements with same class name in a document area?

Click on multiple elements same class name

How to toggle class on multiple elements with same class name on click

How to call on change and on click event from a same class in Jquery?

How to differentiate between multiple elements with the same class using xpath

How to select all elements with jquery where the class starts with a name, has a wildcard in the middle and ends with a name?Check at multiple classes

change text input value based on check box, multiple fields with same class name

How to Select multiple elements with the same class name JavaScript