I have this form
<form name="send" id="myform>
<input type="text" name="data" id="input_field">
<input type="checkbox" value="true" id="my_check">
</form>
I`m sending the information from this form via ajax:
$(function() {
$.post('url.php', {
data : $('#input_field').val(),
check : $('#my_check').val(),
function() {}
});
The problem is that I can`t figure out how to send the form only with #input_field value if #my_check is not checked ?
You syntax is incorrect,
datais an object which contains all data inside of the form for example:Putting that aside, if you use jQuery’s built in
serialize()method to create that data object for you it will ignore non “successful controls”, and this includes unckecked checkboxes:See the W3C definition of successful controls form more information.