Bug Tracker

Modify

Ticket #4523 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

:input selector doesn't work for checkboxes

Reported by: allspiritseve Owned by:
Priority: minor Milestone: 1.3.2
Component: unfiled Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

I'm submitting a form through ajax, using :input to grab all the form values. However, it is not distinguishing whether checkboxes have been checked or not... it just grabs the value anyways.

Change History

comment:1 Changed 4 years ago by allspiritseve

Here's what I'm using, if that helps at all:

$(document).ready(function() {

$('#addtocart').click (function() {

$.ajax ({

type: "POST", url: 'includes/ajaxcart.php', dataType: 'json', data: $(':input'), success: function (result) {

$('#bagcount').text (result.count); alert (result.message);

}

}); return false;

});

});

comment:2 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

The value property of a checkbox (which you are getting indirectly) is the same whether its checked attribute/property is set or not.

If you want the values of all the form elements as they would have been if you submitted the form, look at the formSerialize method in the Forms plugin.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.