<div class="p-2">
<form onsubmit="return handleData()">
<div>
<input type="hidden" name="send_newsletter" value="no">
<input type="checkbox" name="send_newsletter" id="send_newsletter" value="yes" />
<label for="send_newsletter">Subscribe to the newsletter</label>
</div>
<div>
<input type="submit" name="submit" value="Submit"/>
</div>
</form>
</div>
function handleData()
{
var form_data = new FormData(document.querySelector("form"));
console.log("form data: ");
for(var pair of form_data.entries())
{
console.log(pair[0]+ ' : '+ pair[1]);
}
return false;
}
This Pen doesn't use any external JavaScript resources.