2

I have a product attribute named stone_weight. I'm trying to get the value of the attribute based on it's name name="product[stone_weight]" on change event. But it is not triggering any event. How can i properly use any event like change or keyup.

require.config({
        deps: [
            'jquery'
        ],
        callback: function ($) {
            $(document).ready(function(e){
                $('input[name="product\\[stone_weight\\]"]').change(function(e){
                    $stone = $('input[name="product\\[stone_weight\\]"]').val();
                    console.log($stone);
                });
            })
        }
    });
3
  • You have used net_weight instead of stone_weight in above code. Commented Dec 29, 2016 at 9:19
  • please share your code to get more help Commented Dec 29, 2016 at 11:36
  • Sorry. Question edited Commented Dec 29, 2016 at 12:12

1 Answer 1

2

You can try with below code,

 callback: function ($) {
            $(document).ready(function(e){
                $(document).on('change',$('input[name="product[stone_weight]"]'),function(e){
                    $stone = $('input[name="product\\[stone_weight\\]"]').val();
                    console.log($stone);
                });
            })
        }
2
  • Thanks for your help. It really helped me a lot. Kudos... Commented Dec 29, 2016 at 12:47
  • but it's preventing me from saving the value. It is saved as 0. Commented Jan 2, 2017 at 6:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.