0

so I have 9 check boxes which I want to post the data of to my php script and am stuck as to how I would do this? I have found this base:

$.ajax({
  type: "POST",
  url: "check.php",
  data: data,
  success: success,
  dataType: dataType
});

But I don't know how to go about setting that data, success and dataType of that function. I want to be able to send the states/values of my 9 checkboxes as the data and want to be able to call a javascript function which is parsing the output of the post request. This is what my check boxes look like.

<form id="myform">
    <input type="checkbox" id="1" name="1"/>
        <label for="1"><span>1</span></label>
    <input type="checkbox" id="2" name="2"/>
        <label for="2"><span>2</span></label>
    <input type="checkbox" id="3" name="3"/>
        <label for="3"><span>3</span></label>
    <input type="checkbox" id="4" name="4"/>
        <label for="4"><span>4</span></label>
    <input type="checkbox" id="5" name="5"/>
        <label for="5"><span>5</span></label>
    <input type="checkbox" id="6" name="6"/>
        <label for="6"><span>6</span></label>
    <input type="checkbox" id="7" name="7"/>
        <label for="7"><span>7</span></label>
    <input type="checkbox" id="8" name="8"/>
        <label for="8"><span>8</span></label>
    <input type="checkbox" id="9" name="9"/>
        <label for="9"><span>9</span></label>
</form>

Thanks.

1

1 Answer 1

1

if the data is in a form you can serialize the form

var data = $('form').serialize();

see http://docs.jquery.com/Ajax/serialize

Sign up to request clarification or add additional context in comments.

3 Comments

Additionaly, data must be an object: var data = { valueA: inputA.val(), valueB: inputB.val(), [...] };
Only question I need answered now is how I set the success part.
success must be a function success: function(response) { /* What to do with the response */ } Please mark this question as answered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.