Zen Cart Logo
Forums / General Questions / checkout_payment - Uncaught ReferenceError: $ is not defined

checkout_payment - Uncaught ReferenceError: $ is not defined

Views: 1,402

Results 1 to 7 of 7
28 May 2016, 3:19 PM
#1
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

checkout_payment - Uncaught ReferenceError: $ is not defined

This is related to

$(document).ready(function(){
$('form[name="checkout_payment"]').submit(function() {
$('.paymentSubmit').attr('disabled', true);
<?php if ($flagOnSubmit) { ?>
formPassed = check_form();
if (formPassed == false) {
$('.paymentSubmit').attr('disabled', false);
}
return formPassed;
<?php } ?>
});
});

Now... I dont' have jquery on the header... is this the issue ?

Thanks

28 May 2016, 4:14 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: checkout_payment - Uncaught ReferenceError: $ is not defined

Yup. But it should be or should have been there if using ZC 1.5.5 as identified in the breadcrumb of this thread.

What was modified to remove it and why?

28 May 2016, 4:30 PM
#3
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: checkout_payment - Uncaught ReferenceError: $ is not defined

mc12345678:

Yup. But it should be or should have been there if using ZC 1.5.5 as identified in the breadcrumb of this thread.

What was modified to remove it and why?

Sorry, didn't understand....
I didn't remove anything... it's there, but I have my jquery, foundation and all that js stuff loaded at the footer, and I was styling this page, saw a error in chrome.
Wanted to be sure that this was related to that jquery stuff....
So far, I think it's the only file that's complaining about this.
I dont' know javascritp to change this lines, so I could remain with the jquery in the footer.
I've made a test purchase... I don't see no errors on that, so this is changing some attribute on submit, so probably I'll be ok ?
Or perhaps I could just grab this piece of code, and load it in this page on the footer....

28 May 2016, 5:14 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: checkout_payment - Uncaught ReferenceError: $ is not defined

ZC 1.5.5 (as you've at some point come to find out) loads Jquery in the upper area of the page at least in a default template situation. Reload of jquery has negative effects on code loaded between the previous and subsequent code.

Yes, the $ relates to jquery, as to "being ok" if there is an error that is occurring, then something isn't working as designed/expected.

28 May 2016, 5:30 PM
#5
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: checkout_payment - Uncaught ReferenceError: $ is not defined

mc12345678:

ZC 1.5.5 (as you've at some point come to find out) loads Jquery in the upper area of the page at least in a default template situation.

That was (or still is ) on the admin area..... but on front page, again, it's limiting the user choice of template.
Oh well... one can change things, but then on future updates.... it's hell.

Thanks

23 Jan 2018, 3:29 PM
#6
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: checkout_payment - Uncaught ReferenceError: $ is not defined

Hi
After all, I realize that I still have issues with this.
My jquery, etc, as mentioned, is being loaded after the page load

function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "<?php echo DIR_WS_TEMPLATE.'jscript/'; ?>tpl_v02.js";
document.body.appendChild(element);
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;

For whatever reason I now realize that formPassed = check_form(); is not getting defined.

This is the zencart file

$(document).ready(function(){
      $('form[name="checkout_payment"]').submit(function() {
          $('#paymentSubmit').attr('disabled', true);
        <?php if ($flagOnSubmit) { ?>
          formPassed = check_form();
          if (formPassed == false) {
              $('#paymentSubmit').attr('disabled', false);
          }
          return formPassed;
        <?php } ?>
      });

To this what I did now:

// In \includes\modules\pages\checkout_payment\jscript_main.php
<?php 
if ($flagOnSubmit) { ?>
    var flagOnSubmit = 1;        
<?php } ?>
// Portion of this file is loaded on the footer cause jquery

The document.ready

 if (document.body.id === 'checkoutpaymentBody') {
        
        $('form[name="checkout_payment"]').submit(function () {
            $('.paymentSubmit').attr('disabled', true);
            if (flagOnSubmit === 1 && check_form() === false) 
             {
                //document.getElementsByClassName ('payment')
                $('.paymentSubmit').attr('disabled', false);
            }
            console.log(check_form + 'check_form');
            return check_form();
        });
    }

In chromes console check_form() returns true.
Am I doing this right ?

23 Jan 2018, 4:28 PM
#7
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: checkout_payment - Uncaught ReferenceError: $ is not defined

Or maybe the return formPassed; is important ?