1

I am adding multiple text box element with the same class.

It's not working in my project, for demo purpose i added the code to (http://jsfiddle.net/8gbvd/)

Its working there how to debug this issue

Thank you

4
  • Does the navigator inspector return errors ? Commented Dec 3, 2013 at 10:42
  • 1
    Well if the fiddle is working, then you got a working example to compare your code to... the problem is most probably in the differences... My first guess would be that you're actually adding those textboxes dynamically with javascript, while they're hard-coded in you jsfiddle, Am I right ? Commented Dec 3, 2013 at 10:42
  • @Jahnux73 no navigator inspector didn't return errors Commented Dec 3, 2013 at 10:43
  • @Bartdude yes its added dynamically to the table. Commented Dec 3, 2013 at 10:44

2 Answers 2

4

As your textboxes are dynamically added to the page, you need to use delegated events. So

DON'T DO THIS :

jQuery('.qtyBox').change(
    function(){
         alert(jQuery(this).val());
    });

BUT DO THIS INSTEAD :

jQuery('#priceRuleTable').on('change','.qtyBox',
    function(){ 
        alert(jQuery(this).val());
    });

cfr this page for a more detailed explanation on event delegation.

note that if you want to perform an action each time a key is pressed (and not when the user leaves the textbox , you can use the event input instead of change

Sign up to request clarification or add additional context in comments.

Comments

0

If you have same class for multiple select elements and you want to get selected value, only for the changed element, then you can do something as below:

$('#priceRuleTable').on('change', '.qtyBox', function(){
    //to check only selected item is being triggered add css, you can remove it later
    $(this).parent().css("border", "2px solid red");
    //you should get value of the changed select element 
    var v = $(this).parent().find("option:selected").text();
    console.log(v);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.