homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Jquery not working after add or remove on a table

WebmasterWorld Senior Member 5+ Year Member

Msg#: 4636616 posted 12:11 am on Jan 11, 2014 (gmt 0)

I have some buttons that I call ajax with.

Basically I do this

{ url: url,
data: data,
dataType: "json",
type: "POST"
}).always(function(d){CheckHoursStatus(d, action);});
Then in CheckHoursStatus, I either add rows to a table or remove rows from a table based on the action something like this

//this function takes in a status
//if it's an error, it shows the div, otherwise it adds the data
function CheckHoursStatus(d, action){

if(action == "AddHours"){

$("#hoursTable > tbody").append("<tr id='hoursRow" + d.id + "'><td>"+ $("#dayOperation").val() + "</td><td>" + startDate.toLocaleTimeString() +
"</td><td>" + endDate.toLocaleTimeString() + "</td>" + btn + "</tr>");

setTimeout("HideDiv('addHoursOutput')", 5000);
}//if action == AddHours
else if(action == "DeleteOperationHours"){

$("#hourRow" + d.rowid).remove();
}//else if
They both work if you only do one. I.e if you just add all the time, the rows get added. If you remove, the rows get removed. However, as soon as you add a row then remove, nothing happens and vice versa. Any ideas why?



WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

Msg#: 4636616 posted 4:45 am on Jan 11, 2014 (gmt 0)

Haven't looked too closely, but I do notice that your add creates a tr with id "hoursRow" + d.id, while your remove is removing something with id "hourRow" + d.rowid (note, no "s" in that one).

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved