HolisticNetworking.Net: Thomas Belknap's Laboratory of LAMP

Thomas J Belknap’s Laboratory of LAMP

 

A Simple JS Confirmation Button

Because someone asked me and because I haven’t seen quite the same solution out there on the nets, I’m posting this really quick for the benefit of those who need a quick submit button confirmation. If, for example, you want to prompt users to confirm whether or not they wish to delete an item out of a form, you can use the below JavaScript function to get it done. The function is designed to serve as confirmation for many different types of events, so it’s quite flexible:

// confirmButton: simple function to test user response
function confirmButton(message) {
	var conf = confirm(message);
	if(conf) {
		return true;
	} else {
		return false;
	}
}

To us it, I use my trusty Unobtrusive JS action loading function like so:

addEvent(editsubmitbtnz[i], 'click', function() { return confirmButton('Are you sure you want to edit this feed?'); });

You could also add the function directly to the button like so:

<input type="submit" value="Delete This" onclick="return confirmbutton('Are you sure you want to delete this feed?');" />

The result is a JavaScript function that will halt all action on the screen when you hit the submit button that the function is assigned to. It prompts the user to say whether or not they agree with the statement passed as a reference to the function, then pass that value (true or false) back to the page and either submit the form as normal or cancel the operation.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

No comments or trackbacks yet.

  • [[Your comment goes here!]]
Leave a comment or send a note
  1. (required)
  2. (valid email required)
  3. (required)
  4. Send
  5. Captcha
 

cforms contact form by delicious:days

400x80-banner.png