Using jquery in phtml got an error: Uncaught ReferenceError: require is not defined Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?ReferenceError: jQuery is not definedUncaught ReferenceError: jQuery is not definedUncaught ReferenceError: signals is not definedMagento2 : ReferenceError: jQuery is not definedMagento 2: How to submit form on checkbox click?Magento 2 - Update quantity and totals of cart page without page reload?Magento 1.9.1 I have added popup after clicking on addtocart button but the page is reloading before closing the popupUncaught ReferenceError: packaging is not definedReferenceError: jQuery is not defined Magento 2

A German immigrant ancestor has a "Registration Affidavit of Alien Enemy" on file. What does that mean exactly?

Providing direct feedback to a product salesperson

When does Bran Stark remember Jamie pushing him?

Pointing to problems without suggesting solutions

Trying to enter the Fox's den

Protagonist's race is hidden - should I reveal it?

What kind of equipment or other technology is necessary to photograph sprites (atmospheric phenomenon)

Lights are flickering on and off after accidentally bumping into light switch

How to leave only the following strings?

Why do C and C++ allow the expression (int) + 4*5?

Will I be more secure with my own router behind my ISP's router?

Why aren't these two solutions equivalent? Combinatorics problem

Normal Operator || T^2|| = ||T||^2

Why not use the yoke to control yaw, as well as pitch and roll?

What's the connection between Mr. Nancy and fried chicken?

Why doesn't the university give past final exams' answers?

How can I introduce the names of fantasy creatures to the reader?

How to create a command for the "strange m" symbol in latex?

What helicopter has the most rotor blades?

Compiling and throwing simple dynamic exceptions at runtime for JVM

Why did Israel vote against lifting the American embargo on Cuba?

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

Is it OK if I do not take the receipt in Germany?

If gravity precedes the formation of a solar system, where did the mass come from that caused the gravity?



Using jquery in phtml got an error: Uncaught ReferenceError: require is not defined



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?ReferenceError: jQuery is not definedUncaught ReferenceError: jQuery is not definedUncaught ReferenceError: signals is not definedMagento2 : ReferenceError: jQuery is not definedMagento 2: How to submit form on checkbox click?Magento 2 - Update quantity and totals of cart page without page reload?Magento 1.9.1 I have added popup after clicking on addtocart button but the page is reloading before closing the popupUncaught ReferenceError: packaging is not definedReferenceError: jQuery is not defined Magento 2



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I use jquery in my phtml frontend page like this:



<script>
require(['jquery', 'jquery/ui'], function($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click( function(e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function()
if($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options['+id+']" value="'+$(this).val()+'"/> ';

);
if(check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' +model+'&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
</script>


all the function work properly, but in my browser console i got an error pointing at require saying :



VM4522:2 Uncaught ReferenceError: require is not defined









share|improve this question














bumped to the homepage by Community 12 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Which line it's pointing to when you clicked to VM4522:2 Uncaught ReferenceError: require is not defined? And did you clear the static content, redeploy it after your changes were made?

    – Toan Nguyen
    May 4 '17 at 8:02












  • @ToanNguyen the 2nd line require(['jquery', 'jquery/ui'], function($){, ive dont static content deploy numerous time

    – Hunter
    May 4 '17 at 8:04











  • Please execute bin/magento setup:upgrade (to remove static, generation, someother temporary files), then bin/magento setup:static-content:deploy and see if this error still happens.

    – Toan Nguyen
    May 4 '17 at 8:06











  • check this github.com/magento/magento2/issues/1321

    – Qaisar Satti
    May 4 '17 at 8:08












  • @QaisarSatti: Not that issue, obviously.

    – Toan Nguyen
    May 4 '17 at 8:35

















4















I use jquery in my phtml frontend page like this:



<script>
require(['jquery', 'jquery/ui'], function($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click( function(e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function()
if($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options['+id+']" value="'+$(this).val()+'"/> ';

);
if(check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' +model+'&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
</script>


all the function work properly, but in my browser console i got an error pointing at require saying :



VM4522:2 Uncaught ReferenceError: require is not defined









share|improve this question














bumped to the homepage by Community 12 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Which line it's pointing to when you clicked to VM4522:2 Uncaught ReferenceError: require is not defined? And did you clear the static content, redeploy it after your changes were made?

    – Toan Nguyen
    May 4 '17 at 8:02












  • @ToanNguyen the 2nd line require(['jquery', 'jquery/ui'], function($){, ive dont static content deploy numerous time

    – Hunter
    May 4 '17 at 8:04











  • Please execute bin/magento setup:upgrade (to remove static, generation, someother temporary files), then bin/magento setup:static-content:deploy and see if this error still happens.

    – Toan Nguyen
    May 4 '17 at 8:06











  • check this github.com/magento/magento2/issues/1321

    – Qaisar Satti
    May 4 '17 at 8:08












  • @QaisarSatti: Not that issue, obviously.

    – Toan Nguyen
    May 4 '17 at 8:35













4












4








4








I use jquery in my phtml frontend page like this:



<script>
require(['jquery', 'jquery/ui'], function($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click( function(e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function()
if($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options['+id+']" value="'+$(this).val()+'"/> ';

);
if(check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' +model+'&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
</script>


all the function work properly, but in my browser console i got an error pointing at require saying :



VM4522:2 Uncaught ReferenceError: require is not defined









share|improve this question














I use jquery in my phtml frontend page like this:



<script>
require(['jquery', 'jquery/ui'], function($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click( function(e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function()
if($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options['+id+']" value="'+$(this).val()+'"/> ';

);
if(check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' +model+'&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
</script>


all the function work properly, but in my browser console i got an error pointing at require saying :



VM4522:2 Uncaught ReferenceError: require is not defined






magento-2.1 javascript jquery phtml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 4 '17 at 7:56









HunterHunter

799424




799424





bumped to the homepage by Community 12 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 12 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Which line it's pointing to when you clicked to VM4522:2 Uncaught ReferenceError: require is not defined? And did you clear the static content, redeploy it after your changes were made?

    – Toan Nguyen
    May 4 '17 at 8:02












  • @ToanNguyen the 2nd line require(['jquery', 'jquery/ui'], function($){, ive dont static content deploy numerous time

    – Hunter
    May 4 '17 at 8:04











  • Please execute bin/magento setup:upgrade (to remove static, generation, someother temporary files), then bin/magento setup:static-content:deploy and see if this error still happens.

    – Toan Nguyen
    May 4 '17 at 8:06











  • check this github.com/magento/magento2/issues/1321

    – Qaisar Satti
    May 4 '17 at 8:08












  • @QaisarSatti: Not that issue, obviously.

    – Toan Nguyen
    May 4 '17 at 8:35

















  • Which line it's pointing to when you clicked to VM4522:2 Uncaught ReferenceError: require is not defined? And did you clear the static content, redeploy it after your changes were made?

    – Toan Nguyen
    May 4 '17 at 8:02












  • @ToanNguyen the 2nd line require(['jquery', 'jquery/ui'], function($){, ive dont static content deploy numerous time

    – Hunter
    May 4 '17 at 8:04











  • Please execute bin/magento setup:upgrade (to remove static, generation, someother temporary files), then bin/magento setup:static-content:deploy and see if this error still happens.

    – Toan Nguyen
    May 4 '17 at 8:06











  • check this github.com/magento/magento2/issues/1321

    – Qaisar Satti
    May 4 '17 at 8:08












  • @QaisarSatti: Not that issue, obviously.

    – Toan Nguyen
    May 4 '17 at 8:35
















Which line it's pointing to when you clicked to VM4522:2 Uncaught ReferenceError: require is not defined? And did you clear the static content, redeploy it after your changes were made?

– Toan Nguyen
May 4 '17 at 8:02






Which line it's pointing to when you clicked to VM4522:2 Uncaught ReferenceError: require is not defined? And did you clear the static content, redeploy it after your changes were made?

– Toan Nguyen
May 4 '17 at 8:02














@ToanNguyen the 2nd line require(['jquery', 'jquery/ui'], function($){, ive dont static content deploy numerous time

– Hunter
May 4 '17 at 8:04





@ToanNguyen the 2nd line require(['jquery', 'jquery/ui'], function($){, ive dont static content deploy numerous time

– Hunter
May 4 '17 at 8:04













Please execute bin/magento setup:upgrade (to remove static, generation, someother temporary files), then bin/magento setup:static-content:deploy and see if this error still happens.

– Toan Nguyen
May 4 '17 at 8:06





Please execute bin/magento setup:upgrade (to remove static, generation, someother temporary files), then bin/magento setup:static-content:deploy and see if this error still happens.

– Toan Nguyen
May 4 '17 at 8:06













check this github.com/magento/magento2/issues/1321

– Qaisar Satti
May 4 '17 at 8:08






check this github.com/magento/magento2/issues/1321

– Qaisar Satti
May 4 '17 at 8:08














@QaisarSatti: Not that issue, obviously.

– Toan Nguyen
May 4 '17 at 8:35





@QaisarSatti: Not that issue, obviously.

– Toan Nguyen
May 4 '17 at 8:35










1 Answer
1






active

oldest

votes


















0














Try something like this



requirejs(['require'], function (require) 
require(['jquery', 'jquery/ui'], function ($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click(function (e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function ()
if ($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options[' + id + ']" value="' + $(this).val() + '"/> ';

);
if (check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' + model + '&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
);





share|improve this answer























  • It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

    – Ben Crook
    May 4 '17 at 9:51











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f172969%2fusing-jquery-in-phtml-got-an-error-uncaught-referenceerror-require-is-not-defi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try something like this



requirejs(['require'], function (require) 
require(['jquery', 'jquery/ui'], function ($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click(function (e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function ()
if ($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options[' + id + ']" value="' + $(this).val() + '"/> ';

);
if (check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' + model + '&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
);





share|improve this answer























  • It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

    – Ben Crook
    May 4 '17 at 9:51















0














Try something like this



requirejs(['require'], function (require) 
require(['jquery', 'jquery/ui'], function ($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click(function (e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function ()
if ($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options[' + id + ']" value="' + $(this).val() + '"/> ';

);
if (check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' + model + '&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
);





share|improve this answer























  • It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

    – Ben Crook
    May 4 '17 at 9:51













0












0








0







Try something like this



requirejs(['require'], function (require) 
require(['jquery', 'jquery/ui'], function ($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click(function (e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function ()
if ($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options[' + id + ']" value="' + $(this).val() + '"/> ';

);
if (check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' + model + '&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
);





share|improve this answer













Try something like this



requirejs(['require'], function (require) 
require(['jquery', 'jquery/ui'], function ($)
var currentUrl = '<?= $itemEditUrl ?>';

$('#link-cusom-campaign').click(function (e)
e.preventDefault();
var check = 1;
var optionsInput = '';
$('select[name^="options"]').each(function ()
if ($(this).val() == '')
check = 0;
$("<p style='color:red;' class='alert-empty'>This is a required field</p>").insertAfter(this).delay(3000).fadeOut();
else
var name = $(this).attr('name');
var id = parseInt(name.match(/[0-9]+/));
optionsInput += '<input type="text" name="options[' + id + ']" value="' + $(this).val() + '"/> ';

);
if (check == 1)
var model = $('#select_18').val();
var qty = $('#qty').val();
var getUrl = currentUrl + '?model=' + model + '&qty=' + qty;
var form = $('<form action="' + currentUrl + '" method="post">' +
optionsInput +
'<input type="text" name="qty" value="' + qty + '" />' +
'</form>');
$('body').append(form);
form.submit();

);
);
);






share|improve this answer












share|improve this answer



share|improve this answer










answered May 4 '17 at 9:29









Hammad KhalidHammad Khalid

382111




382111












  • It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

    – Ben Crook
    May 4 '17 at 9:51

















  • It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

    – Ben Crook
    May 4 '17 at 9:51
















It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

– Ben Crook
May 4 '17 at 9:51





It doesn't seem right for Require JS to require Require JS (sounds like a tongue twister), even if this works it seems like more of a workaround than a fix :(

– Ben Crook
May 4 '17 at 9:51

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f172969%2fusing-jquery-in-phtml-got-an-error-uncaught-referenceerror-require-is-not-defi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її