jQuery undesired effect from 'tr td:first-child' -
i have dynamic html
table create in php
query. after it's created user can click edit button , cells become editable. when they're done press save button , loop initiates running through data , storing in array. almost works, there small problem of getting value of job# column, it's putting both values in 1 index of array. made fiddle show process jsfiddle , illustrate problem. can see it's storing numbers in last index. need of them, them stored 1 @ time each have own individual index in array.
also post code down here, though fiddle linked more useful
var saveedits = []; $('#table_edit_projects').click(function () { $('#create_project').hide(); $('#table_edit_projects').hide(); $('#save_project_te').show(); $('#cancel_save_project_te').show(); $('.editable_content_td').attr('contenteditable', 'true'); $('.editable_content_td').addclass('blue_td'); }); $('#save_project_te').click(function () { $('#save_project_te').hide(); $('#cancel_save_project_te').hide(); $('#create_project').show(); $('#table_edit_projects').show(); $('.editable_content_td').attr('contenteditable', 'false'); $('.editable_content_td').removeclass('blue_td'); $('.editable_content_td').each(function () { saveedits.push($(this).text()); }); var id = $('.contenttable tr td:first-child'); saveedits.push($(id).text()); $.each(saveedits, function (index, value) { alert(index + ': ' + value); }); /*this used send data , update table in database $.ajax({ url:'core/functions/update_projects.php', type: 'post', data: {'saveedits': saveedits}, done: function(data) { // testing } }).fail (function() { alert('error'); }).always(function(data) { alert(data); }); */ saveedits = []; });
the problem here selector $('.contenttable tr td:first-child')
chooses every 1 of elements , gets text of them, resulting in 16 17
seeing.
my suggestion change couple of things: push id array adding additional selector:
$('.editable_content_td, .content_td a').each(function () { saveedits.push($(this).text()); });
then remove code have getting id - id should @ start of array
Comments
Post a Comment