Many of the questions for Impromptu are concerning how exactly to use Impromptu as a confirm to remove an element from a list(database or just the dom). Its actually pretty easy, and so I whipped up an example of removing users from a database. Each user has a userid which I pass to the php file, the php file passes back true/false if it was successful. Then we remove the user from the html dom or either throw an error message. The examples can be found here, just view the source for the code:
Delete users from a list
http://www.trentrichardson.com/Impromptu/demos/demo1.html
Edit users from a list
http://www.trentrichardson.com/Impromptu/demos/demo2.html
Related posts:


13 Responses
Chris
29|Oct|2007 1Trent, you rock!
I’ll take a closer look but this appears to be exactly what I was looking for.
Thanks for your help, really appreciate it.
Chris
Chris
01|Nov|2007 2Trent,
Ive implemented the modal delete box and it works nice and I really like the edit example as well and I’ll be implementing that as well.
I have 1 last item I was wondering if you could help me with that I’m sure others must come across when doing web apps.
Basically I have a system that allows admin people to manage things like articles, faqs etc and they always want to be able to order them as they see fit. For example they would want to see 1 article show up above another when displayed out on a webpage. In the past I always utilized a system whereby they inputted a number (display precedence) and based on this, that is how they were outputted.
What I would like to do is simply allow them to drag and drop a and have that update the dbase accordingly. So there might be say 10 articles listed out and the user could simply and visually see the order and if necessary simply click on 1 article and drag it to wherever they wish and upon releasing it the dbase would get updated. I’m not sure if you’ve tackled this one before and I’m sure it’s a bit more complex (especially the updating of the dbase) Where I get lost is that I’m sure I need to somehow get the order of the div id’s and based on that loop through and update the dbase but just not grasping it.
Thanks for your help and I plan on providing a few impromptu design samples as well for others to use.
Chris
trent
01|Nov|2007 3Hi Chris,
It appears you are looking for something like:
http://jquery.com/plugins/project/NestedSortable
Click “Try out a demonstration” for some samples. If that’s not exactly what you’re looking for you may want to try jQuery UI as it also has a sortable plugin. or Interface:
http://interface.eyecon.ro/demos
Each time the sortables are reordered they should pass the new list of items back to you in their correct order via their callback function. Then just as you did with Impromptu you will make an ajax post to update your database. Hope that helps! I also look forward to seeing your Impromptu designs!
Bryan
14|Jan|2008 4Hey there. Before I show this keep in mind I’m a total newbie at Javascript. But I copied your code and modified it slightly, and am having a TON of trouble getting the edit function to do anything.
http://cosmeticalchemy.com/retailers/dashboard.php
Any help you could give on why the submission on edit is not going through would be GREATLY appreciated. Just click on the first product name.
Thank you SOOOOO much.
Bryan
trent
14|Jan|2008 5Hey Bryan,
It looks like in your editPrompt() your id for editname is wrong, one says editproduct(prompt text), the other says editname(in the submit validation). Hope that helps! Looks good!
Trent
Martin Sarsini
22|Feb|2008 6something wrong here I suppose…
$.post(‘removeuser.php’,{userid:uid}, callback:function(data){
trent
22|Feb|2008 7Hey Martin,
I have that commented out since I didn’t write the php side to the script. If you’re trying to get the php side to work then be sure you’re printing out “true” or “false” from the php. Also you might want to add $.trim() to that if statement:
$.post(‘removeuser.php’,{userid:uid}, callback:function(data){
if($.trim(data) == ‘true’){…
Martin Sarsini
22|Feb|2008 8Hi Trent
I am getting an error exactly on that line and on the click of the “delete” nothing happens at all apart from receiving an error.
I removed callback: leaving just function(data) and it works great.
I am using jquery 1.2.3
trent
22|Feb|2008 9It could be a difference in versions of jQuery, that example runs on 1.2.1. It’s getting about time for me to update the examples again.
Martin Sarsini
29|Feb|2008 10Trent, can I ask you how can I get the php file to send back data to the original script?
// if($.trim(data) == ‘true’) {
trent
29|Feb|2008 11Hey Martin,
the $.post will call the php file:
$.post(‘removeuser.php’,{userid:uid}, callback:function(data){
then in the call back the “data” function parameter will have the output of the php file, so within your php file if the action is successful you can do echo “true”; or echo “false”; if the action is not successful. For this script it is only looking for a one word response. You could however create xml, but then you will need to parse it on the jquery side. I was shooting for the simplest possible example.
Ethan From Malaysia
26|Mar|2009 12Hi, Trent, this is the correct callback function to use after my test
$.post(“vars.php”, { userid: uid }, function(data) {
if(data == ‘true’) {alert(data);}
else{ $.prompt(‘An Error Occured while removing this user’); }
});
Sample vars.php
Hope this help someone. :)
Ethan From Malaysia
26|Mar|2009 13oops.. for vars.php, simply echo false then the callback will get the respond
Leave a reply