Submitting a multi dimensional array with jQuery and YUI -
hey guys, bugging me if me out amazing.
i'm using jquery , yui , i'm trying send multidimensional array via json php reason can't grab text put in array span! go figure! no matter how try can't seem add it. if manually add test data weekdays0 = , works reason wont grab text span!
the alert on click works , outputs information out of span can't seem set array value
function checkday(checkbox) { var checked = '0'; if ($('#' + checkbox).is(':checked')) { checked = '1'; } else { checked = '0'; } return checked; } var weekdays = new array(7); weekdays[0] = new array(); weekdays[0][0] = checkday('chxmonday'); weekdays[0][2] = $('#results22monday').text(); weekdays[1] = new array(); weekdays[1][0] = checkday('chxtuesday'); weekdays[1][3] = new array(); weekdays[1][4] = $('#results22tue').text(); weekdays[2] = new array(); weekdays[2][0] = checkday('chxwednesday'); weekdays[2][5] = $('#results22wednesday').text(); weekdays[3] = new array(); weekdays[3][0] = checkday('chxthursday'); weekdays[3][6] = $('#results22thursday').text(); weekdays[4] = new array(); weekdays[4][0] = checkday('chxfriday'); weekdays[4][7] = $('#results22friday').text(); weekdays[5] = new array(); weekdays[5][0] = checkday('chxsaturday'); weekdays[5][8] = $('#results22saturday').text(); weekdays[6] = new array(); weekdays[6][0] = checkday('chxsunday'); weekdays[6][9] = $('#results22sunday').text(); weekdays = yahoo.lang.json.stringify(weekdays); $('#btnupdatesettings').click(function () { alert($('#results22tue').text()); $.ajax({ data: { contactid: d.act_contactid, apicpolicy: $('[name=txtcpolicy]').val(), apinewregistrations: $('[name=rdoregister]').val(), apiinterval: $('[name=cbobooking]').val(), apimaxdate: $('[name=cbomaxdate]').val(), apitimes: weekdays, method: 'updatewebbooking', datatype: 'json' }, success: function () { console.log("welldone, you've updated!"); }, error: function () { alert("ooooppps!"); } }); });
when check console logo screen below, showing array empty.
i've marked space want text appear not there! infuriating. same goes other array results
any ideas you'd helping me out
update
the alert work , outputs show below, not added array!
so i'm still non wiser not being added.
update
that's weird, have index set 1 below when pasted code question first time index change! odd! anyway, not working when array indexes correct!
var weekdays = new array(7); weekdays[0] = new array(); weekdays[0][0] = checkday('chxmonday'); weekdays[0][1] = $('#results22monday').text(); weekdays[1] = new array(); weekdays[1][0] = checkday('chxtuesday'); weekdays[1][1] = new array(); weekdays[1][1] = $('#results22tue').text(); weekdays[2] = new array(); weekdays[2][0] = checkday('chxwednesday'); weekdays[2][1] = $('#results22wednesday').text(); weekdays[3] = new array(); weekdays[3][0] = checkday('chxthursday'); weekdays[3][1] = $('#results22thursday').text(); weekdays[4] = new array(); weekdays[4][0] = checkday('chxfriday'); weekdays[4][1] = $('#results22friday').text(); weekdays[5] = new array(); weekdays[5][0] = checkday('chxsaturday'); weekdays[5][1] = $('#results22saturday').text(); weekdays[6] = new array(); weekdays[6][0] = checkday('chxsunday'); weekdays[6][1] = $('#results22sunday').text();
update
ok feel need give guys more comprehensive question fill in on i'm trying there more eloquent way achieving this. images below best way show this. when press update table button populates blank area on right table includes check boxes @ increments set earlier on in form. these check boxes want save along whether check box day has been checked. if day unchecked want table cleared no data sent database day. thats why wanted save in multidimensional array , serialize them, can' work
please try alert - $('#results22monday').text();
because, in opinion, .text() culprit.
can see, json created in correct format(7,2 array) , checkday function populating values correctly.
so please check
- which htmlelement results22monday , others?
- does have text? or need val()?
oh, wanted 7 x 2 array right?
if so, indexing of child array wrong.
try altering 1 line , tell me if first value shown @ firebug console?
weekdays[0][2] = $('#results22monday').text();
to
weekdays[0][1] = $('#results22monday').text();
see wanted results22monday second element of child array(ie. @ index 1)
i rewrite top part of code this, since lot cleaner.
function checkday(checkbox) { return ($('#' + checkbox).is(':checked')) ? '1' : '0'; } var weekdays = new array(7); weekdays[0] = [checkday('chxmonday'), $('#results22monday').text()]; weekdays[1] = [checkday('chxtuesday'), $('#results22tue').text()]; weekdays[2] = [checkday('chxwednesday'), $('#results22wednesday').text()]; weekdays[3] = [checkday('chxthursday'), $('#results22thursday').text()]; weekdays[4] = [checkday('chxfriday'), $('#results22friday').text()]; weekdays[5] = [checkday('chxsaturday'), $('#results22saturday').text()]; weekdays[6] = [checkday('chxsunday'), $('#results22sunday').text()]; //as not practice re-initialise same variable var jsonedweekdays = yahoo.lang.json.stringify(weekdays);
Comments
Post a Comment