I have two cookies in this form, one is Text, one is a radio button selection. The text cookie works fine, but the radio button does not.
How its supposed to work: Input text, make a selection, press button. Sends you to next page where the text is displayed, and the associated number of the radio button is displayed.
What is actually happening: Input text, make a selection, press buton. Sends you to next page where the text is displayed, but there is nothing from the radio button selection.
Thank you ahead of time.
JSfiddle - http://jsfiddle.net/q7nja8j9/
HTML -
<form action="javascript:void(0)">
<input type="text" name="cookie" id="cookie" value="">
<div id="pics">
</div>
<div id="radio">
<input type="radio" name="char" id="char1" value="1">
<input type="radio" name="char" id="char2" value="2">
<input type="radio" name="char" id="char3" value="3">
</div>
<input type="button" name="Fight" id="saveCookie" value="Fight" onclick="window.location.href='Battle.html'">
</form>
JS-
$(function(){
// attach event listener to save cookie button
$('#saveCookie').click(function(){
// set cookie expiration to 1 year from today
var expDate = new Date();
expDate.setFullYear(expDate.getFullYear() + 1);
// create cookie string
var cookieStr = $('#cookie').val() + ";expires=" + expDate.toGMTString();
// create cookie
var cookieChar = $('input[name="char"]:checked').val() + ";expires=" + expDate.toGMTString();
document.cookie = cookieStr;
document.choice = cookieChar;
});
});