Modal Cookie Uncaught SyntaxError: unexpected token: identif


Topic: Modal Cookie Uncaught SyntaxError: unexpected token: identifier

demzl25 pro premium asked 2 weeks ago

Hi

I have created Modal cookie snippet and the Modal is not working and console is showing ERROR "Uncaught SyntaxError: unexpected token: identifier".

*_Actual behavior_*Here is link to snippet: https://mdbootstrap.com/snippets/standard/demzl25/3931181#js-tab-view

Thanks,

Damjan


Grzegorz Bujański staff commented 2 weeks ago

Unfortunately, the code you added does not work. I tried to fix it but there are more bugs - it seems the snippet is not full and some parts are missing. The error you are writing about is not visible in the console.


demzl25 pro premium commented 2 weeks ago

Thanks

I have converted this js from jquery and is not working without jquery library.

Is it possible to get it working without jquery library?

This is original jquery code:

$(document).ready(function(){if(document.cookie.indexOf("gdpr_mandatory=")==-1){$('#gdpr_basic').modal({backdrop:false});}});$('#gdpr_btn_full_agree').click(function(e){e.preventDefault();var date=new Date();date=new Date(date.getTime()+1000*60*60*24*365);document.cookie="gdpr_mandatory=1; expires="+date.toGMTString()+"; path=/";document.cookie="gdpr_functional=1; expires="+date.toGMTString()+"; path=/";document.cookie="gdpr_ga=1; expires="+date.toGMTString()+"; path=/";document.cookie="gdpr_fbp=1; expires="+date.toGMTString()+"; path=/";$('#gdpr_basic').modal('hide');});$('#gdpr_btn_adjust').click(function(e){e.preventDefault();$('#gdpr_basic').modal('hide');$('#gdpr_adjust').modal();});$('#gdpr_btn_save').click(function(e){e.preventDefault();$('#gdpr_adjust_form').submit();});$('#gdpr_adjust_form').on('submit',function(e){e.preventDefault();$(this).find('input[type="checkbox"]').each(function(e){var fieldName=$(this).attr('name');var fieldValue=$(this).is(':checked')?1:0;var date=new Date();date=new Date(date.getTime()+1000*60*60*24*365);document.cookie=fieldName+"="+fieldValue+"; expires="+date.toGMTString()+"; path=/;";})toastr["info"]("Saved");$('#gdpr_adjust').modal('hide');});

I have put this js code in this snippet and i get this error in the console "Uncaught ReferenceError: $ is not defined"

Thanks,

Damjan


Grzegorz Bujański staff commented 2 weeks ago

I create snippet: https://mdbootstrap.com/snippets/standard/grzegorz-bujanski/3939420#html-tab-view I added jQ in it, but I still don't see the error you are writing about


demzl25 pro premium commented 2 weeks ago

Thanks,

Yes you don't see the error I m writing about because you have added jquery library as asset if you remove jquery library error is present. My question is, is it possible to run (or covert to plain java) this js script for gdpr cookies without jquery library so that I don't need to add complete jquery library to the project?


Grzegorz Bujański staff commented 2 weeks ago

Yes, it is possible. The JS code has disappeared from the snippet you send. Add it there again, I will check what you have already added and make corrections.


demzl25 pro premium commented 2 weeks ago

I have added js here is link to snippet: https://mdbootstrap.com/snippets/standard/demzl25/3943388#html-tab-view

Thanks


Grzegorz Bujański staff commented 2 weeks ago

In this snippet, I only see jQ code which has not yet been converted to pure JS. It is not possible to use jQ code without importing the jQ library. In the previous snippet, you already had code changed to pure JS. I meant this code. It will take us a long time to change the entire code. Our support was created to help in case of problems with our components, or in the case where you have already started doing something but have a problem due to errors. If you want us to rewrite this code from jQ to pure JS from scratch, we can offer such help for a fee as part of our services: https://mdbootstrap.com/services/


demzl25 pro premium commented a week ago

I didn't understand you clearly witch snippet you where referring. I have this snippet converted into pure js but it has some errors so i need help with this.

I have put this converted js to this snippet: https://mdbootstrap.com/snippets/standard/demzl25/3958434#js-tab-view

I'm puting here also the original Jquery snippet:

$(document).ready(function(){if(document.cookie.indexOf("gdpr_mandatory=")==-1){$('#gdpr_basic').modal({backdrop:false});}});$('#gdpr_btn_full_agree').click(function(e){e.preventDefault();var date=new Date();date=new Date(date.getTime()+1000*60*60*24*365);document.cookie="gdpr_mandatory=1; expires="+date.toGMTString()+"; path=/";document.cookie="gdpr_functional=1; expires="+date.toGMTString()+"; path=/";document.cookie="gdpr_ga=1; expires="+date.toGMTString()+"; path=/";document.cookie="gdpr_fbp=1; expires="+date.toGMTString()+"; path=/";$('#gdpr_basic').modal('hide');});$('#gdpr_btn_adjust').click(function(e){e.preventDefault();$('#gdpr_basic').modal('hide');$('#gdpr_adjust').modal();});$('#gdpr_btn_save').click(function(e){e.preventDefault();$('#gdpr_adjust_form').submit();});$('#gdpr_adjust_form').on('submit',function(e){e.preventDefault();$(this).find('input[type="checkbox"]').each(function(e){var fieldName=$(this).attr('name');var fieldValue=$(this).is(':checked')?1:0;var date=new Date();date=new Date(date.getTime()+1000*60*60*24*365);document.cookie=fieldName+"="+fieldValue+"; expires="+date.toGMTString()+"; path=/;";})toastr["info"]("Saved");$('#gdpr_adjust').modal('hide');});

Thanks

Today i have try to make free consultation from the link you sent me but the contact form is not working (cannot sent email because sent button is not working).


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Open

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 4.0.0
  • Device: Pc
  • Browser: Chrome 97.0.4692.99
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes