0

My custom module:

app\code\Zero\my_module\view\frontend\web\js\changezipcode.js

define(['jquery'], function ($) {
    'use strict';
        $(document).ready(function() 
        {
            $('#form').hide();
                 $("#changeButton").click(function() {
                     $("#form").toggle('slow');
                 });

                 $("#submit").click(function() {
                    var zipcode= $("#zipcode").val();
                    alert("Value: " + zipcode);
                });
        });
});

app\code\Zero\my_module\view\frontend\requirejs-config.js

var config = {
    map: {
        '*': {
            changezipcode:   'Zero_my_module/js/changezipcode',
        },
    }
};

Onclick event not triggered.

2 Answers 2

0

In your requirejs-config.js file add dependency of jQuery like this

var config = {
paths: {
    'changezipcode': 'Zero_my_module/js/changezipcode'
},
 shim: {
    'changezipcode': {
        deps: ['jquery']
    },
}
};

After this, when you will call changezipcode it will be dependent on jquery

2
0
 require([
           "jquery",
           'Zero_my_module/js/changezipcode'
       ], function ($, firebase) {
           'use strict';
       $(document).ready(function() 
       {
           $('#form').hide();
                $("#changeButton").click(function() {
                    $("#form").toggle('slow');
                });

                $("#submit").click(function() {
                   var zipcode= $("#zipcode").val();
                   alert("Value: " + zipcode);
               });
       });

3

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.