1

I am creating a small CRM that has many AJAX-powered forms. I am trying to establish the best neutral data selection tool for getting all data for a form.

One issue I am having is that checkboxes always come up as "on" when doing $('#checkbox').val(). My goal is to write 1 selection that will get all items that have data within them. My current selection statement is quite bare:

$('input, select, textarea').each( function() {
    // do stuff with the data, and create a dataString
}

I have tried using :not(), but what I really want to do is get ALL input tags that are NOT unchecked checkboxes. Is there some nested selector I can use? I know :checked is always available, but I was trying to keep it as non-specific as possible. I know i could do:

$('input[type=text], input:checked, type[type=hidden] .... ')

And so on, but I'm looking to keep it nice and short (if possible!)

Thanks guys!

Eric Holmes
  • 415
  • 7
  • 21
  • Do you want the query to return radio buttons (unchecked or checked)? – semao Jul 02 '13 at 14:31
  • the idea is to eventually include radio buttons as well (only selected), but the forms I have created so far only feature the items mentioned above. :) – Eric Holmes Jul 02 '13 at 14:41

1 Answers1

1

Try using $('form#myForm').serializeArray(), which ignores unchecked boxes. As does $('form#myForm').serialize().

bgun
  • 99
  • 3
  • Thank you! What is the difference between `serializeArray()` and `serialize()`? jQuery vs native? any speed differences? – Eric Holmes Jul 02 '13 at 15:44
  • Found the answer - `serialize()` returns a string, it seems! Very cool. http://stackoverflow.com/questions/10430502/whats-the-difference-between-serialize-and-serializearray – Eric Holmes Jul 02 '13 at 17:09