Many people are perhaps still a little unclear of what jQuery Impromptu really is. Its not just a lightbox or dialog. Its actually a small framework to process forms utilizing ajax; and along the way it happened to solve the ugly default confirm and alert problem.

It works by first allowing the user to supply html for display in the prompt. The user can supply as many fields as they like and style them to fit their needs. Then, with strategic callback functions you can validate and/or complete the prompt form. The common framework example is generally defined like the following:


$.prompt(txt,{ 
	buttons:{Ok:true, Cancel:false},
	submit: function(v,m){
		//parameter v is the value clicked, m is the message at the time it was submitted
		//validate our fields, return true if it validates, false if not
		//returning false will hold the prompt open
		//returning true will proceed to the callback function
	},
	callback: function(v,m){
		//we passed validation process our form!
	}
});

This small framework will allow you to process forms consistently, so no matter what type form you’re processing, you can they all follow the same process. Taking it one step further, lets say we need to retrieve all the values in our form so we can validate them. We would add a line like the following:


$.prompt(txt,{ 
	buttons:{Ok:true, Cancel:false},
	submit: function(v,m){
		var vals = m.find(':input');
		if(v){
			//user clicked 'Ok', so validate
		}
	},
	callback: function(v,m){
		var vals = m.find(':input').serializeArray();
		if(v){ //send with Ajax!
			$.post('mypage.php',{ var0: vals[0].value },function(){});
		}
	}
});

There you have it, about as simple as it gets for ajax forms. Download it and give it a whirl, or look at a couple demos.