Tuesday, December 30, 2008

[jQuery] Posting multiple values from a checkbox

I've got checkboxes on my page. When I use the $.post method, it's
only transmitting the first value out of my list. Here's my code:

$.post("http://localhost/search_engine.php",{
food_type: $("#food_type").val(),
foods: $(":checkbox").fieldValue(),
}, function(xml) {
displayResult(xml);
});

the checkboxes look like this:

<input type=checkbox id=foods value="apples'>Apples
<input type=checkbox id=foods value="Pizza'>Pizza
<input type=checkbox id=foods value="Cake'>Cake

If I check all three, I only get the first one, although if I do an
alert of

$(":checkbox").fieldValue()

I get back all the results I selected.

I'm using the jquery form library jquery.form.js.

Should I be posting this data some other way? Or is my syntax wrong?

Thanks,

No comments: