I really stink at javascript. I have 2 functions. Can someone help me combine into 1. Individually they work fine seperately. first I want to prompt a confirmation.. function confirmAction(){ var confirmed = confirm("Are you sure you want to delete?"); return confirmed; } function remove_this(id) { var string_post = "UPDATE mytbl SET status='0' WHERE Id='" + id+"'"; row_deactivate(string_post, function(){sel_prod()}); } I tried doing this but doesnt work. function remove_this(id) { var confirmed = confirm("Are you sure you want to delete?"); return confirmed; var string_post = "UPDATE mytbl SET status='0' WHERE Id='" + id+"'"; row_deactivate(string_post, function(){sel_prod()}); } thanks.
The smart thing to do would then be to post your solution to this thread - that way, if people search for stuff, and happens upon your thread, they would benefit from your solution. Also, if your solution is inneficient or error-prone, or something akin those lines, somebody might see it and say "hey, you, you might wanna do it this way instead".
ok. Im glad you posted because actually my solution did not work correctly. I ended up just doing this : function remove_this(id) { confirmAction(); var string_post = "UPDATE mytbl SET status='0' WHERE Id='" + id+"'"; row_deactivate(string_post, function(){sel_prod()}); } but what happens is regardless of whether i click yes or no the update query still runs. I need a way to stop both functions from running if no is clicked.
Step 1, lose the "function for nothing" crap -- it's a waste of code, execution and download time. Step 2, you don't actually USE the result from that extra function for nothing... "well there's your problem..." -- if you don't do a IF, you're confirm dialog isn't gonna do jack. function remove_this(id) { if (confirm("Are you sure you want to delete?")) { row_deactivate( "UPDATE mytbl SET status='0' WHERE Id='" + id + "'", function() { sel_prod(); } ); } } Code (markup): You have to IF the confirm's result, and put what you want done on 'yes' inside the IF. Also avoid making functions and extra variables when you don't have to... Though I'm absolutely horrified from a security standpoint seeing a query in JavaScript...