Cookie on submit and on close modal

Hi, I have a code that stores a cookie for a day when the modal is closed which works but I also want to add the code where once I submit form it stores a cookie forever but it doesn’t work. below is the code(it works with the submit part as comment).

<script>
//modal cookie
	var cookieName = 'modalClosed';
  
  if(typeof Cookies.get(cookieName) !== 'undefined'){
  		$('.signup_component').remove();
    }
    
    //$('.signup_form-block').submit(()=>{
		//Cookies.set(cookieName, 'forever', { expires: 360 })
		//$('.signup_component').remove();
    
    $('.signup_close-button, .signup_background-overlay').on('click', function(){
    		Cookies.set(cookieName, 'stored', { expires: 1});
    })
    
    
    
</script>

Here is my site Read-Only: LINK
(how to share your site Read-Only link)

Hi,

The problem might happen as in the commented code you’re using arrow function syntax (() => {}). This expression is a bit limited and might cause some errors, so if you’re not fully aware of how it works, it’s safer to use the function expression

Try to rebuild the arrow function to a normal one so it looks as follows:

$('.signup_form-block').submit( function() {
Cookies.set(cookieName, 'forever', { expires: 360 })
$('.signup_component').remove();
}

If you need any further help with implementation, feel free to reach us here:

1 Like

thanks this worked! this ) was missing at the end.