I have a form like this:
<form id="loginCompact" action="https://externalsite..." name="sportsbook" method="post" onsubmit="createCookie('BRLOG', document.sportsbook.username.value, 1)">
<input type="text" name="username" class="loginUsername" />
...other fields...
</form>
And this is the Javascript function that’s called:
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/; domain='mydomain.com'";
}
</script>
However, the cookie is not getting set when the form is submitted. It was working fine when attached to the onclick handler of the button, but not on onsubmit. Any ideas?
I figured this out – I needed to put a full stop in front of the domain, and lose the quotes: