I need to set a cookie using a sumbit button, i have the code and I just cant get it to run.

Could you take a quick look at it and let me know if theer is a glaring problem.

The button code:

Code:
<input type = "submit" value = "Submit" onclick = "setCookie()" />
The cookie set code:

Code:
window.onload = usercookieset; //calls function usercookieset to either create cookie or check the value
                
        function usercookieset(){ //sets the function
            var userName = "";//declares the variable with a null value
            if (document.cookie != ""){//tests the value of the cookie to see if its not set to null
                userName = document.cookie.split ("=")[1];
                
            document.getElementById("username").value = userName;//retrieves the value of the username text field and stores it in the userName variable               
               }
        
        
        function setCookie(){ //function that is called to run the above function
            var expireDate = new Date();//gets the date and stores it as a variable
            expireDate.setMonth(expireDate.getMonth()+12);//sets the expiry time of the cookie
            
            var userName = document.getElementById("username").value;
	        document.cookie = "userName=" + userName + ";expires=" + expireDate.toGMTString();
        }