Hello
I would like to set a cookie when a user submits a form.
I am working with some legacy code that sets a cookie based on a user checking a checkbox, but would like this to simply set the cookie when a user submits a form.
Here is what i have, which works when a checkbox is checked:
$().ready(function()
{
$('.application-form').submit(function(e)
{
e.preventDefault();
if ($('.application-form input[name=marketing]').is(':checked'))
{
$.cookie('agreed_to_terms', '1', { path: '/', expires: 999999 });
}
});
});
This works fine, but i don't want the cookie set when checking the "marketing" input, rather just when the form submits. Like this:
$().ready(function()
{
$('.application-form').submit(function(e)
{
e.preventDefault();
if ($('.application-form').submit();)
{
$.cookie('agreed_to_terms', '1', { path: '/', expires: 999999 });
}
});
});
However, this does not set the cookie successfully, any ideas would be great,thanks.