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);
                });
            })
        }
    });
  • You have used net_weight instead of stone_weight in above code. – Rakesh Jesadiya Dec 29 '16 at 9:19
  • please share your code to get more help – Rakesh Jesadiya Dec 29 '16 at 11:36
  • Sorry. Question edited – Shiyas Pathiyassery Dec 29 '16 at 12:12
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);
                });
            })
        }
  • Thanks for your help. It really helped me a lot. Kudos... – Shiyas Pathiyassery Dec 29 '16 at 12:47
  • but it's preventing me from saving the value. It is saved as 0. – Shiyas Pathiyassery Jan 2 '17 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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