jQuery Impromptu 2.7 is now available. I’ve added a few new features:
- $.prompt.getCurrentState()
- $.prompt.getCurrentStateName()
- option.timeout
Option.url didn’t make the cut simply because I’ve not figured out the best way to approach this. I’ll post any progress on this solution.
Related posts:


116 Responses
Ben K
18|Jun|2009Hi Tren,t
Just a quick question, I’m using states and I want to run a script on the very first load of the prompt. Whats the best way to do that?
using loaded does that execute on everytime the state is visited?
cheers,
Ben
trent
18|Jun|2009Hey Ben,
There are a couple ways to do this. options.loaded will run when the prompt is shown. It is at the end of the entrance animation effect.
However if you want to execute some code before its shown(because there’s an animation on the entrance the prompt is actually there as soon as $.prompt is called) we could do the following:
$.prompt(‘some stuff here..’);
$(‘#mydate’).datepicker();
Basically the loaded option runs after you can actually see the prompt, the second method runs before you see the prompt. Hope that helps!
trent
18|Jun|2009Sorry the answer to the second question is no, loaded is only executed once when the prompt initially opens. If you need something on every state change you will have to do so in the submit functions.
Ben K
18|Jun|2009thanks trent,
It’s ok I wanted it to only run once, was just putting the loaded option in the wrong spot, got it right now though!
thanks again for your help!
Max
19|Jun|2009Sorry, I come from China, English is not very good.
I like your project, but the project in IE6, every time it occupied about 7M of memory, and memory will not be recovered.
Do you have a better way?
simon
19|Jun|2009Sorry, SUPER SUPER STUPID QUESTION:
I am trying to sample your demo1.php from http://trentrichardson.com/Impromptu/demos/demo1.php
but I am getting the error ” $ is not defined”.
All I did was download the html source and changed these 2 lines:
To point to the location of where I downloaded jquery libraries.
What am I missing?
Thanks and sorry for the basic question.
-S
simon
19|Jun|2009SORRY, figured it out. Had the jscript library in the wrong folder.
Thanks again. Your code is awesome!
simon
19|Jun|2009Just donated ;-)
trent
19|Jun|2009Simon,
Hey, glad you got it working. Thanks for the donation!!!
trent
19|Jun|2009Max,
I’ve not noticed any performance issues so far with ie6. However when I run ie6 with Wine sometimes Wine runs wild. I am unable to simulate this, has anyone else encountered this problem?
Are you able to run a simple example successfully in ie6?
$.prompt(‘test’);
KenderTas
22|Jun|2009Hi.. thanks for this code!
Question: how can I get form fields to be returned “serialized” ?
I know I can get form fields values (f.NAME), but they’re not serialized…
I think this is the clue:
$jqi.find(‘#’+ options.prefix +’states :input’).serialize();
but I don’t know how to implement it…
After a few tests, I tried this:
//collect all form element values from all states
[..cut..]
forminputs['impSerialized'] = $jqi.find(‘#’+ options.prefix +’states :input’).serialize();
but i think it’s not a good approach…
I need to get something like: key1=val1&key2=val2&key3=Dungeons+%26+Dragons
I don’t know how to serialized string directly in jquery, because:
f.NAME_OF_FIELD.serialize() => not working
or
f.serialize() => not working..
any others method?
bye!
trent
22|Jun|2009You shouldn’t have to do any searching, the variables will be gathered for you. The f variable comes from the submit or callback parameter:
$.prompt(‘html here…’,{
submit(v,m,f){ //f is here..
}
});
Make sure you have a name attribute to all your html elements though within the string passed in:
$.prompt(‘<input type=”text” name=”foo” id=”foo” value=”hello” />’,{
submit(v,m,f){ //f is here..
alert(f.foo);
}
});
trent
22|Jun|2009if you’re using this for an ajax request you can just pass in f:
$.prompt(’<input type=”text” name=”foo” id=”foo” value=”hello” />’,{
submit(v,m,f){ //f is here..
$get(‘mypage.php’,f,callback(data){});
}
});
f will look like this:
f = {
foo: ‘hello’
}
KenderTas
22|Jun|2009Thank you.. the only thing I didn’t try was the easier way… simply using the “f” :)
indeed the “f” is already serialized!
bye!
vfrog
29|Jun|2009Hate to break it to you, but pressing “enter” in a text field normally submits the form, be it an actual HTML form, a modal dialog or Joe’s JQuery Widget o’the Week
trent
30|Jun|2009vfrog,
You’re right, Impromptu is not a true form. However, there have been many advances made to restrict tabbing out of the prompt and to have default buttons. Perhaps in the next release we can improve on this.
Michael
30|Jun|2009Hi Trent,
This may be more of a javascript question but have tried everything I can think of. I’m trying to integrate Impromptu into a cart I am working with. This is part of a larger bit of javascript code that is executed when a button is clicked:
$.prompt(‘Your item has been added to the cart’, {prefix:’cleanblue’, timeout: 4000})
window.location.reload();
What happens is here is that the popup comes up quickly then fades for FF and Safari, not at all for IE. The 4 second is pause is ignored and the reload just happens. Is there something else I should do with Impromptu to make sure the timeout is not ignored?
Thanks.
trent
30|Jun|2009Hey Michael,
Impromptu can’t stop execution of javascript, and sense you’re not using a button click within the prompt the submit and callback options probably won’t work either. Try changing that window.location.reload to:
setTimeout(“window.location.reload()”,4100);
This will wait for the prompt to close before reloading.. You might have to play with the amount of time to get it working exactly right.
Michael
30|Jun|2009Thanks Trent, I had a feeling but needed to confirm.
tep
01|Jul|2009hi trent,
first thanks for light and efficient plugin :)
when i call your plugin within ie6 , select items are being to invisible, i tried to add useiframe:true but it did not work and interesting thing at the left corner of the screen was displayed “false” ??
what is the problem ?
trent
06|Jul|2009I’ve had other users mention this as well, though I haven’t noticed it. Are the select boxes in the prompt or in the page underneath?
ryan
08|Jul|2009In the ‘states survey demo’ how would you manipulate the javascript to post the data collected to an e-mail address would you have to change the if statement in state 3 where v==1?
state3: {
html:’Please leave any other comments you have about this site:’,
buttons: { Back: -1, Cancel: 0, Finish: 1 },
focus: 2,
submit:function(v,m,f){
if(v==0)
$.prompt.close()
else if(v==1)
return true; //POST TO E-MAIL HERE?
else if(v=-1)
$.prompt.goToState(‘state2′);//go back
return false;
}
}
}
trent
08|Jul|2009Ryan,
All form fields that have been collected in the prompt are in the submit function parameter f. so you might do:
state3: {
html:’Please leave any other comments you have about this site:’,
buttons: { Back: -1, Cancel: 0, Finish: 1 },
focus: 2,
submit:function(v,m,f){
if(v==0)
$.prompt.close()
else if(v==1){
//first you might want to validate your email address here..
//lets say the email is in a field called ‘email’ it will be located in f as f.email
//if email is invalid return false so prompt doesn’t close..
// else…
$.post(‘myEmailSender.php’,{ emailaddr: f.email }, function(data){});
return true; //POST TO E-MAIL HERE?
}
else if(v=-1)
$.prompt.goToState(’state2′);//go back
return false;
}
}
}
myEmailSender.php will be your serverside file that will send the email
ryan
08|Jul|2009So the PHP file located on the server will have to include echo’s for each separate f. parameter?
trent
09|Jul|2009no, in your javascript you should have an input box in the html option for that state
state3: {
html:’Email: <input type=”text” name=”email” id=”email” value=”" />’,
buttons: { Back: -1, Cancel: 0, Finish: 1 },
focus: 2,
submit:function(v,m,f){
if(v==0)
$.prompt.close()
else if(v==1){
//first you might want to validate your email address here..
//lets say the email is in a field called ‘email’ it will be located in f as f.email
//if email is invalid return false so prompt doesn’t close..
// else…
$.post(‘myEmailSender.php’,{ emailaddr: f.email }, function(data){});
return true; //POST TO E-MAIL HERE?
}
else if(v=-1)
$.prompt.goToState(’state2′);//go back
return false;
}
}
}
Jon Anderson
10|Jul|2009Hi Trent…
I’ve been using Impromptu and it’s been working great for Safari, but now I can’t get it to work in FF or IE at all. Any idea what I might have changed that would cause this? Previously, it *kinda* worked (ugly but doable) but now it doesn’t pop up at all.
Thanks for any advice you can offer..
trent
14|Jul|2009Jon,
Are you getting any errors? Does it show anything at all, just not styled?
tep
17|Jul|2009@Trent:21
Q: Are the select boxes in the prompt or in the page underneath?
A: in the page underneath.
One more issue. I would like to set buttons text for multilanguage but could not do it.
is there any sample ?
for example i am using lang function for multi language as shown below . lang(“ok”) gives an error :(
$.prompt(lang(“Sure_Delete”),{ buttons: { “ok”: true, “cancel”: false }, focus: 1 });
trent
17|Jul|2009You may have to create your buttons object the long way.. for example:
var mybuttons[lang("ok")] = true;
mybuttons[lang("cancel")] = false;
$.prompt(lang(”Sure_Delete”),{ buttons: mybuttons, focus: 1 });
Hope that helps!
tep
17|Jul|2009not worked :(
may be syntax error ?
var mybuttons[lang("ok")] = true;
mybuttons[lang("cancel")] = false;
trent
17|Jul|2009what kind of error is it giving?
tep
17|Jul|2009says “expected ;” bracket for [ in var mybuttons["ok"] = true;
trent
17|Jul|2009try this instead:
var mybuttons = {};
mybuttons[lang("ok")] = true;
mybuttons[lang("cancel")] = false;
$.prompt(lang(“Sure_Delete”),{ buttons: mybuttons, focus: 1 });
tep
18|Jul|2009Great, that’s it :)
Thanks Trent !
Sen
20|Jul|2009Hey Trent,
Great work!
Is there a way to call the submit function, instead of clicking on the ‘Ok’ button?
In fact, I put a textarea in the box, and I want to call a submit function whenever the ‘enter’ key is used.
Thanks for your help.
My code:
$.prompt(‘New texttest’,
{ submit:function(v,m,f)
{
if (f == null) return;
// …
}
});
function watchEnterKey(__event)
{
if (__event.keyCode == 13)
{
// $.prompt.submit(); <— I need that kind of function!
return(false);
}
return(true);
}
trent
20|Jul|2009Sen,
This is somewhat of a flaw of Impromptu. Since Impromptu is made for many different submit options.. (some work needs to be done on this part I admit). You were close however with your effort. try this:
if (__event.keyCode == 13)
{
$(‘#OkButtonID’).click();
}
in your function just find the button you want to click and manually call the click event.
Sen
21|Jul|2009Wonderful, it works very well!
Thanks a lot, Trent.
Jon Anderson
23|Jul|2009Hey Trent, how would I make a simple login prompt? This is not meant for high security, but just a stopper for a test page.
It should behave something like an htaccess prompt except only the password field:
1. Pops up on page load
2.Asks for password (and uses one submit button, no ability to close popup window)
3. If correct, allows page to load/display
4. If incorrect, just says “incorrect” but never allows access to page.
Thanks for any help you can offer!
Jon Anderson
23|Jul|2009Almost forgot:should only popup once per session.
trent
24|Jul|2009Hey Jon,
Sorry I don’t have much time to respond this morning, I’ll try to address later today. Sounds like you need to check to see if a cookie exists. If there is no cookie do the prompt. otherwise they are already logged in.
When the prompt opens within your prompt you should have a password field. Your submit function should look similar to this:
function(v,m,f){
if(v){ //ok button was clicked
if(f.password == ‘MYPASSWORD’){
//set the cookie here
return true;
}
return false;
}
}
this is sort of pseudo code, there are a ton of examples for setting cookies
Jon Anderson
24|Jul|2009Good enough for me. Thanks Trent!
Mike
28|Jul|2009Quick question:
I’m using a textarea field in the string (just like the comment box in your survey example). However, when I use prompt to output the html, I get a comma “,” appended to the result. This only happens for the textarea, not any of the regular inputs. There’s only one textarea with the name as well.
If I have a value say… Default, if I input “hello”, I get “hello,default”.
Any ideas?
Thanks,
Mike
Ed G.
28|Jul|2009I’m having the same issue with select boxes in the underlying form. They are being hidden when $.prompt displays. They reappear ok with a button action, but do not reappear when using $.prompt.close().
This is only happening in IE (using 7). Firefox appears to work without a hitch.
Ed G.
28|Jul|2009I did create a workaround – so I thought I’d post it.
In a body onload function I put the following set the a loaded function to redisplay the selects in my form:
$.prompt.setDefaults(
{ loaded: showselects }
);
function showselects(){
var form=document.getElementById(MyFormId’);
var nbr_elems = form.elements.length;
for(var i=0;i<nbr_elems;i++)
{
if(form.elements[i].type == ‘select-one’){
form.elements[i].style.visibility = ‘visible’;
}
}
}
dennis
29|Jul|2009Hi Trent,
I was trying to give the button names dynamically but i couldn’t. I hava a function like:
function ConfirmationLink(message, href, firstButton, secondButton)
{
$.prompt(message,{
buttons:{firstButton:true,secondButton:false},
callback: function(v,m){
if(v) window.location = href;
}
});
}
i give the firstButton name from the onclick option of . When i do like that, if i check the firstButton with alert(firstButton), i can see that i change the name successfully. But at the prompt window, the button names are firstButton and secondButton.
Is there a way to change the names?
deef
29|Jul|2009Dennis, I had the same problem – reading some of the comments above, this is the solution:
function myConfirm(labelMessage, labelYes, labelNo, destinationUrl) {
var mybuttons = {};
mybuttons[labelYes] = true;
mybuttons[labelNo] = false;
$.prompt(labelMessage, { buttons: mybuttons, focus: 1, submit: function(v,m,f){ if (v) document.location.href=destinationUrl; } });
}
dennis
29|Jul|2009Deef,
Thank you very much.
trent
29|Jul|2009Mike,
Sounds like broken html somewhere(perhaps the string you’re passing in to Impromptu?) Do you have it available online to look at?
Ed G.,
This stems back from ie6 hacks I believe. When I get a chance to dive back into the code for another update This is a first priority. Thanks for posting your fix.
Deef,
Thanks for posting your solution for Dennis.
Mike
29|Jul|2009Thanks for the response Trent — I still am not able to figure it out, so I’ll paste some code:
var txt = ‘Pass: Pass1 ‘;
txt += ‘Pass2′;
var pass1txt = ‘Number ‘;
var optionaltext = ‘Paste additional info: Status, Emails … ‘;
pass1txt += optionaltext;
var states = {
state0: {
html: txt,
buttons: {Next: true},
focus: 0,
submit: function (v,m,f) {
if (f.pass == ‘pass1′) $.prompt.goToState(‘state1′);
return false;
}
},
state1: {
html:pass1text;
buttons: { Back: -1, Finish: 0 },
focus: 1,
submit: function(v,m,f) {
if (v==-1) $.prompt.goToState(‘state0′);
if (v==0) return true;
return false;
}
}
};
$.prompt(states, {
callback: function (v,m,f) {
var str;
$.each (f, function(i,obj) {
str+=i + ” – ” + obj + ““;
});
$.prompt(str);
}
For the last prompt(str), all of the values except that of the TextArea are OK; the text area has the ‘randomly appended comma’.
Sorry for so much pasting, if it’s too much, please try to point me in the right direction.
Thanks,
Mike
Mike
29|Jul|2009I don’t think it’s an html problem — Somewhere along the line, the TextArea object has more than one value…
If I do f.addinfo, I get “string,”. But when I do f.addinfo[0], I just get “string”, which is what I want. I was just wondering why it’s an array , when addinfo is the only element with that name.
Thanks,
Mike
trent
29|Jul|2009You’re right, it does sounds like there is more than one input field with the same name or id. When Impromptu gathers inputs if there is more than one with the same name (checkboxes) it creates an array of values. Can you use the contact form at the top and email me the text you’re passing to Impromptu?
Mike
29|Jul|2009Sent, let me know if you didn’t receive it.
Mike
29|Jul|2009I have figured it out… Sorry for the bother … In my html code, I append additional info twice. (for different states). That’s where the array and commas come into play.
Thanks for your time -
Mike
trent
29|Jul|2009Excellent! glad you got it sorted out!
Mike
30|Jul|2009Hi I’m back again :)
Is there any way to make the prompt box ‘movable’ , i.e., have a window edge at the top?
Mike
trent
30|Jul|2009Mike,
I’ve not done this before, but it would definitely require a plugin to do so. You might look at jquery ui for such:
http://jqueryui.com/demos/draggable/
Using that plugin you might try:
$.prompt(‘some text’);
$(‘#jqi’).draggable();
Not sure how that will work but its a start..
Mike
30|Jul|2009Thanks Trent, that worked off the bat.
Matt
10|Aug|2009Hi,
First of all thanks for this plugin it makes my alert’s a lot nicer (all i am using it for at the mo but will more than likely expand the use for some other stuff when I get the hang of it!). However I need a bit of help.
I have a form in which the user will input some data, this is checked after hitting the submit button for; length of word, email address etc, if all the fields are correct then it put the data into a database. At this point I would like to display a arlert box that says the data has been inputted correctly.
I have got this to work with a normal (ugly!) Javascript alert box but cant seem to get it to work with Ipromptu.
Thanks in advance!
trent
10|Aug|2009My guess is that a native alert box can pause processing, where impromptu can’t. To fix this don’t actually send the form until the callback of the $.prompt. In otherwords when the submit button is clicked return false so the button doesn’t fire the form submission. Show the prompt. In the callback of the prompt do $(‘#myFormEl’).submit();
Matt
11|Aug|2009Thanks Trent,
Will try that out, that seems to be what I was trying to acheive as an alternative.
Cheers
GDorn
13|Aug|2009Is there any way to tell Impromptu to use an existing div instead of creating an overlay? I want the nice interface for prompting the user, but I don’t want to block the rest of my app in the meantime.
trent
13|Aug|2009GDorn
Unfortunately there aren’t any options for that. You can try tweaking the css for the overlay and do display:none; on the fade. Then they should be able to get to the page underneath
Mike
14|Aug|2009Hi Trent, I’m back!
It’s more HTML related, but all I’m trying to do is increase the size of a textarea (Large comments box). I’ve been playing around with css, html rows / columns, but can’t seem to adjust the size to what I want it to be.
Any hints?
Thanks,
Michael
trent
15|Aug|2009Hey Mike,
Sounds like you should be able to do something like the following in your css file:
.jqi textarea{ height: 200px; width: 200px; }
.jqi is if you’re using the default “prefix” option with Impromptu.
Mike
15|Aug|2009Thanks!
Aydin
16|Aug|2009Hi Trent;
I am trying to sample your demo1.php [ http://trentrichardson.com/Impromptu/demos/demo1.php but I am getting the error :
Error: missing ) after argument list
Code:
$.post(‘removeuser.php’,{userid:f.userid}, callback:function(data){
I did delete the “callback:” and tried. It’s work. But this time, record is successfully removing but returning prompt error:
“An Error Occured while removing this user”
What am I missing?
Thanks and sorry for the basic question.
Aydin
17|Aug|2009I have removeuser.php and it’s work normally.
trent
17|Aug|2009Excellent, glad its working!
Robin A.
17|Aug|2009Trent,
I’ve been a desktop programmer for quite a while and now I’m caught in the web world and would like to give your scripts a try but I don’t know where to start.
I have a form with the following:
The checkfields() is the javascript function that is run to check the user’s input. The check_data.php is run if checkfields() returns true. It is working well with regular javascript but I’m trying to use your alert() and confirm but I can’t get the daiglog boxes to popup.
I have this in the HEAD section of the HTML file.
Your help would be appreciated in getting this to work.
Thanks,
Robin.
tep
19|Aug|2009hi again trent,
i would like to call submit function while press enter key in password field via code below
$(“#password”).live(“keypress”, function(e) {
if(e.keyCode==13) {
mysubmitfunc;
return false;
}
});
what shall i do for passing v,m,f parameter values ?
thanks
tep
trent
19|Aug|2009Hey Tep,
The easiest way would be to just trigger the click event for the submit button:
$(‘#which_ever_button’).click();
Robin A.
20|Aug|2009trent,
Sorry about the last message. It was an error on my part. It is looking good now, but I don’t have the images referenced in the CSS file. Could you point me in the direction to download the images?
Thanks,
tep
20|Aug|2009hımm nice trick
but the button comes with prompt function how can i reach it ?
$.prompt(txt,{submit: mysubmitfunc, buttons: { Ok:true }});
trent
20|Aug|2009You can use firebug to get the generated id of the button. As long as you haven’t changed the prefix option they should be consistent. You can access it like so:
$(‘#jqi_state0_buttonOk’).click();
the “Ok” at the end will be whatever you named your button, so that should be correct for your example
trent
20|Aug|2009Which theme are you using?
Robin A.
20|Aug|2009trent,
I’m using the light brown theme.
Thanks,
Robin.
trent
20|Aug|2009There is one image which is used twice. Here’s the link to it:
http://trentrichardson.com/Impromptu/images/brown_theme_gradient.jpg
Robin A.
20|Aug|2009Thanks trent, I hope I can make this work.
You’ve done an excellent job. I’ve tried other alert/confirm replacements and was not satisfied. Yours has a lot more potential for what I want to do.
Thanks again,
Robin
tep
20|Aug|2009as you mentined id is jqi_state0_buttonOk
it worked ! thanks :)
Dennis
25|Aug|2009Hi Trent,
I have a div like:
When i do like that:
var text = $(‘#container’).html();
$.prompt(text, { callback: myFunction });
function MyFunction(){
var value = $(‘#myInput’).val();
}
the value returns empty. Am i missing something?
Dennis
25|Aug|2009Upps html inputs are not accepted i guess.
there is a div with id “container” and it has an input text element with id “myInput”. :)
Dennis
25|Aug|2009Div’s content did not appear. I don’t know why.
div (‘container’) has an input text element with id=’myInput’.
Lucas H.
26|Aug|2009Hey Trent,
Love impromptu man!
Totally awesome, but I do have one question.
Right now I am using it to display some dynamically built information and sometimes the height of the impromptu box goes below the page break on the screen. When this happens I am not able to get down to the buttons I have at the bottom. Is there a way to make the content of the box scroll in impromptu, or any other options?
Thanks for your help. Talk to you soon.
Peace,
Lucas
tep
28|Aug|2009“Microsoft JScript runtime error: Object doesn’t support this property or method”
the error above seems to be known problem ?
only in IE ; when i call click event for Ok button via $(“#jqi_state0_buttonOk”).click() within password enter key event
it gets an error
any comment ?
trent
01|Sep|2009Sounds like a variable might not be loaded yet. Just double checking are all script files at the top? and Impromptu included after jquery?
tep
01|Sep|2009yes , at the top and jquery before impromptu (otherwise it does not work)
:(
Sammy
03|Sep|2009Trent, great stuff here! I’m using Impromptu to handle alerts and confirmations for a SharePoint based shopping cart. It’s working beautifully with one exception:
When I’ve scrolled down the page and call a prompt, the fade and alert box appear from the top of the page, so that I have to scroll up to confirm the alert.
I’m using the example CSS, unmodified, from your site. I noticed your prompts samples (1-16) perfectly. The answer is in the CSS, I know it. Any ideas?
trent
08|Sep|2009Hey Sammy,
At first thought I wonder if the bottom of the page is cleared (refering to css like when there are absolute positioned or floating objects) and jquery cannot get a good read on the height of the body. Try running on page load just alert($(‘body’).height()); just to see if that returns a value that seems appropriate.
Sammy
16|Sep|2009Hey Trent… Yes, I checked the page heights via the prescribed jquery method. All pages report “732″ for their body heights.
Sergei
19|Sep|2009Hey Trent!!!
how submit data form, for example in Demo States – Survey?????Tell Please!!!!
trent
21|Sep|2009Hey Sergei,
to submit form data for a prompt with states is very similar to a basic prompt. the f parameter on your “callback” function will contain form values from all states. Then use the callback function at the end to send your form data. Take a look at the source for this example:
http://trentrichardson.com/Impromptu/demos/survey.php
Sammy
29|Sep|2009Trent,
For SharePoint usage, you have to declare a DOCTYPE (XHTML 1.0 Transititonal) to get Impromptu to function as intended.
Once the DOCTYPE was set, Impromptu worked flawlessly inside SharePoint!
Best,
Sam T.
vaske
05|Oct|2009If I try to close prompt on [x] I got this error
Object is undefined, jquery error on 666 line
[object XULElement]
and after that only page refresh would helps…
any suggestion about this?
trent
05|Oct|2009Sounds like the html string passed in may have a syntax error?
Panos
31|Oct|2009Im very new in JQuery and I’m trying to make it work for the last 3 days!!!
I’ m trying this and it works fine (without removing the data from the db)
function removeUser(id){
var txt = ‘Are you sure you want to remove this user?’;
$.prompt(txt,{
buttons:{Delete:true, Cancel:false},
callback: function(v,m,f){
if(v){
var uid = f.userid;
//Here is where you would do an ajax post to remove the user
//also you might want to print out true/false from your .php
//file and verify it has been removed before removing from the
//html. if false dont remove, $promt() the error.
//$.post(‘removeuser.php’,{userid:f.userid}, callback:function(data){
// if(data == ‘true’){
$(‘#userid’+uid).hide(‘slow’, function(){ $(this).remove(); });
// }else{ $.prompt(‘An Error Occured while removing this user’); }
//});
}
else{}
}
});
}
But when Im trying this do nothing on click!
function removeUser(id){
var txt = ‘Are you sure you want to remove this user?’;
$.prompt(txt,{
buttons:{Delete:true, Cancel:false},
callback: function(v,m,f){
if(v){
var uid = f.userid;
$.post(‘removeuser.php’,{userid:f.userid}, callback:function(data){
if(data == ‘true’){
$(‘#userid’+uid).hide(‘slow’, function(){ $(this).remove(); });
}else{ $.prompt(‘An Error Occured while removing this user’); }
});
}
else{}
}
});
}
This is what I have in my removeuser.php
Where am I wrong? Help me please!!!
Panos
31|Oct|2009my removeuser.php
include (“../../../resources/inc/config.php”);
$db = mysql_connect($db_host, $db_user, $db_pass) ;
mysql_select_db ($db_name) or die (“Cannot connect to database”);
$query = “DELETE FROM crosslinks WHERE id = $_POST[userid]“;
$result = mysql_query($query,$db);
mysql_close($db);
trent
02|Nov|2009Hey Panos,
Have you tried placing some alert(‘test’); through your callback function to see how far it makes it? if it makes it within the $.post callback try alert(data) and see if it gives you a php error.
pefstra
02|Nov|2009Hi, I am very new in ajax/jquery. I have this and it works fine. How can I add a prompt/confirm before deletion with impromptu? Can you help me please? Thanks!!!
$(document).ready(function() {
$(‘a.listControl’).click(function(e) {
e.preventDefault();
var parent = $(this).parent();
$.ajax({
type: ‘get’,
url: ‘links_actions.php’,
data: ‘ajax=1&delete=’ + parent.attr(‘id’).replace(‘listItem-’,”),
beforeSend: function() {
parent.animate({‘backgroundColor’:'#cc0000′, ‘color’:'#ffffff’},300);
},
success: function() {
parent.slideUp(300,function() {
parent.remove();
});
}
});
});
});
trent
03|Nov|2009Pefstra,
within your link click event call the $.prompt. Similar to the following:
$(’a.listControl’).click(function(e) {
$.prompt(‘my message here’,{
buttons: { Ok:true, Cancel:false},
callback: function(v,m,f){
if(v){//if Ok was pressed
//your ajax call
}
}
});
});
pefstra
04|Nov|2009Thank you so much Trent!!! Your script is the best!
Panos
06|Nov|2009I have the same problem as Aydin (66) but I dont understand how to solve the problem…
Jon Anderson
11|Nov|2009Hey Trent, thanks again for Impromptu; it’s been great!
I’m stumped trying to create a simple password form. I know it’s insecure, but in this case it really doesn’t matter. I just want a password field and a submit button. If it passes, they see the page. If it doesn’t, it just gives an error and asks for the pw again.
Can you help out? I’ve been able to muddle my way through all of this but I’m still a bit of a JS noob :)
Thanks!
Jon Anderson
11|Nov|2009Are you going to make me donate again? :)
trent
11|Nov|2009Hey Jon,
I will try to work you up a quick example tonight. My workday has been hectic, sorry.
Jon Anderson
11|Nov|2009Awesome, thanks Trent! You’ll help alleviate part of my workday..
trent
11|Nov|2009Jon, I’ve posted a quick example here:
http://trentrichardson.com/Impromptu/demos/demologin.php
Jon Anderson
12|Nov|2009Pefect! Thanks!
trent
15|Nov|2009Panos,
Sounds like just a syntax error somewhere.
Hugo
04|Dec|2009Hi. Your plugin is very very good.
It would have been nice to be able to specify width and height using plugin parameters. You can’t have a bunch of styles for each size you’ll need. Great job!
Hugo
05|Dec|2009Is it possible to avoid users to close the message box by pressing ESC key? It really breaks the modal philosophy. Thank you.
trent
05|Dec|2009Hey Hugo,
Currently height and width are not options but are worth considering adding in the next version. To change on the fly is simple though..
$.prompt(‘test’).find(‘#jqi’).css({ width: 500, height: 300 });
I guess escape key press should be included within the persistent option. (the persistent option keeps the prompt from closing when you click outside the prompt). I should also check then option when the esc key is pressed. If you need to fix this urgently it would be really simple to fix:
Near Line 124 in the non-minified version you should see this line:
//escape key closes
if(key==27) {
removePrompt();
}
Also check for the option in the key code:
//escape key closes
if(key==27 && !options.persistent) {
removePrompt();
}
Hope this helps, although its not an elegant solution. I will fix this in the next release!
trent
05|Dec|2009Or better yet just replace that call to removePrompt() with fadeClicked(), it already checks for the persistent option and will then hightlight the buttons when esc is pressed
//escape key closes
if(key==27) {
fadeClicked();
}
S.Sahin Cetin
12|Feb|2010Hi everyone
you have a question. I’m trying to combine the two applications. “” Is it possible to include into javascript? I give the address to be included in your application needed. Is this possible? I thought to place the application’s address: http://bowser.macminicolo.net/ ~ jhuckaby / jpegcam / test_resize_enlarge.html
Brian Markham
02|Aug|2010I have included the impromptu script but when I execute the prompt is comes up with no styling ??
$.prompt(‘Your recipe has been saved’);
Please help ????
Mikel
31|Jan|2011Hello, when my yes button was clicked, it doesn’t execute my ajaxload function.also,it doesn’t execute promptOptions function using loaded option..please help..here is my code..
function promptOptions()
{
var searchbox_x = $(“#searchbox_iframe”).width()/2 + “px”;
var searchbox_y = $(“#body-layout-container”).height()/2 + “px”;
var top = “200px”;
var prompt_options = {
left: searchbox_x,
top: “100px”
};
return prompt_options;
}
$(‘.sk_btn4′).bind(‘click’,
function(e)
{
e.preventDefault();
$.prompt(‘Sind Sie sicher, die Sie löschen möchten?’,{ buttons: { Yes: true, No: false },
loaded: promptOptions,
submit: function(v,m,f){
if (v === true) {
ajaxLoad(this.href, ‘bindFavoritesButtons’);
} else {
return false;
}
}
});
}
);
Mikel
31|Jan|2011I’ve already solved the problem..Thanks anyway.. the problem is with this.href so what I did is to assign it first into a variable before I actually use it in ajaxLoad function..