homepage Welcome to WebmasterWorld Guest from 54.196.199.46
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
andrewsmd




msg:4636618
 12:11 am on Jan 11, 2014 (gmt 0)

I have some buttons that I call ajax with.

Basically I do this

$.ajax(
{ 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>");
}

$("#addHoursOutput").fadeIn("medium");
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?

 

Fotiman




msg:4636646
 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