form submit tutorial example

http://phpschool.com/link/tipntech/78427

by Rob Sedgwick

HTML

<form name="myform" method="post" onsubmit="dogs(); return false;">
    <input type="checkbox" name="Question1" id="Answer1" value="Answer1"  />
    <label for="Answer1">Answer 1</label>
    <br/>
    <input type="checkbox" name="Question1" id="Answer2" value="Answer2"  />
    <label for="Answer2">Answer 2</label>
    <br/>
    <input type="checkbox" name="Question1" id="Answer3" value="Answer3"  />
    <label for="Answer3">Answer 3</label>
    <br/>
    <input type="submit" />
</form>

CSS

.center{text-align:center;margin-top:1em;}

JavaScript

var form = document.forms.myform,
    elem = form.elements;


form.onsubmit = function(){

    
    alert('thanks to test.');
    dogs();
    return false;
}


function dogs() {

    var arrCB = {};

    $("input[name='Question1']:checked").each(

    function () {
        var id = this.id;
        arrCB[id] = (this.checked ? 1 : 0)
    });

    var text = JSON.stringify(arrCB);
    alert(text);
}