I’ve been developing this phonegap app and I’m stuck with a few things and one of them is multiple checkboxes – I hope you can help.
I’ve got the below code
HTML
<input type="date" id="date" /> <input type="hidden" id="hidden"> <fieldset id="oyuncuKategori"> <legend>Kategori</legend> <div class="roundedOne"> <input type="checkbox" id="oyuncu" name="kategori" value="oyuncu" class="squareTwo" /> <label for="oyuncu">Oyuncu</label> </div> <div class="roundedOne"> <input type="checkbox" id="yardimci_oyuncu" name="kategori" value="yardimci_oyuncu" class="squareTwo" /> <label for="yardimci_oyuncu">Yardımcı oyuncu</label> </div> <div class="roundedOne"> <input type="checkbox" id="cocuk_oyuncu" name="kategori" value="cocuk_oyuncu" class="squareTwo" /> <label for="cocuk_oyuncu">Çocuk oyuncu</label> </div> <div class="roundedOne"> <input type="checkbox" id="stand_hostesi" name="kategori" value="stand_hostesi" class="squareTwo" /> <label for="stand_hostesi">Stand hostesi</label> </div> </fieldset>
JavaScript
$("input[type='date']").on("change", function () { // var checkbox = $("#oyuncuKategori").serialize(); var checkboxes = ''; $('input[name=kategori]:checked').each(function(i, e) { checkboxes += '&node[field_kategorisi][und][value]='+$(this).val(); }); console.log(checkboxes); monthNames = [ "Oca", "Şub", "Mar", "Nis", "May", "Haz", "Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara"]; date = new Date($("input").val()); day = date.getDate(); monthIndex = date.getMonth(); year = date.getFullYear(); finalDate = day + ' ' + monthNames[monthIndex] + ' ' + year; $.ajax({ url: 'http://www.rejicast.com/services/node.json', type: 'post', dataType: 'json', data: 'node[type]=oyuncu&node[title]=testnomikos456&node[language]=und'+ checkboxes +'&node[field_dogum_tarihi][und][0][value][date]=' + finalDate +', success: function (data) { console.log(JSON.stringify(data)); }, error: function (xhr, status, message) { console.log(xhr); console.log(status); console.log(message); } }); });
The thing is, this code works for creating a node but and inserts values for field_kategorisi overwriting other values, thus always the last checked box is there, while trying with [und]['+i+'][value]
gives me 406: An illegal choice has been detected. Please contact the site administrator
. and something like Illegal choice Array in field_kategorisi
(I don’t remember the English wording) on the server side. I’m really stumped. Can you give me any ideas?
UPDATE: When I make an ajax call, my POST looks like this.