Page 1 of 1

Dsiplaying a confirmation message

Posted: Mon Apr 03, 2006 11:23 am
by Michael_C
I have been asked to provide a confirmation message prior to a table commit. If the user confirms, the table update occurs, if not, they can alter their form edits. This request sounds simple enough, but I suspect it's not when working with a web app environment. Is there a simple way to handle this without the user losing their form edits upon cancel?

One thought I had was to never leave the form, and just change the visibility of the form objects in java script.
Do form objects have a visible property? Can I have three buttons, "Ok", "Cancel", "Do It" on the form, where only the "Do It" button is initially visible. Pressing "Do It" will execute java code to change the confirm message visibility, set the "Do It" visible prop to false, and "Ok", "Cancel" to true.

Is this even possible? Is there an easier way?

Any examples I can look through that deal with this?

Am I making it tougher than it really is?

Michael

Posted: Tue Apr 04, 2006 2:59 am
by Weirdan
assuming you have a <form> submitting your data:

Code: Select all

<form action="something.php" method="POST" onsubmit='return confirm("Are you really really sure?");' >
  
   <!-- form elements here -->

</form>
notice the onsubmit form attribute.

Posted: Tue Apr 04, 2006 9:21 am
by Michael_C
Weirdan wrote:assuming you have a <form> submitting your data:

Code: Select all

<form action="something.php" method="POST" onsubmit='return confirm("Are you really really sure?");' >
  
   <!-- form elements here -->

</form>
notice the onsubmit form attribute.
Thankyou. This is much easier/cleaner than what I ended up doing. Is there a way to make this a dynamic message?

I have a two line message that can have essentially 3 message types. Within these three types, there are more specific variations. I am storing the messages in a couple text boxes which I display when needing confirmation. Is there a way to output the message using the onsubmit contained in a form object?

Code: Select all

document.getElementById('txtConfirm').value = lcMessage ;
document.getElementById('txtConfirm1').value = lcSecondLine ;
Thanks again,
Michael

Posted: Wed Apr 05, 2006 12:52 am
by Michael_C
Got it, never mind my previous post

Posted: Wed Apr 05, 2006 1:57 am
by RobertGonzalez
What happens if your users have disabled javascript? Or if they are using user agents that do not support javascript (PDA, Cell Phones, etc)? Have you given any consideration to server-side confirmations? One good point is that they are independent of the browser. Of course, one drawback is they require another trip to the server. But at least you know that the confirmation will always fire.

Posted: Wed Apr 05, 2006 2:29 am
by timvw
I find http://www.onlinetools.org/articles/uno ... pter1.html quite interesting. Basically, i don't have any javascript in my html markup but i attach it all when the script is loaded (actually, i attach when the document onload event occurs).

Posted: Wed Apr 05, 2006 10:41 am
by Michael_C
Everah wrote:What happens if your users have disabled javascript? Or if they are using user agents that do not support javascript (PDA, Cell Phones, etc)? Have you given any consideration to server-side confirmations? One good point is that they are independent of the browser. Of course, one drawback is they require another trip to the server. But at least you know that the confirmation will always fire.
I think the saying "I know enough to be dangerous" applies. It's possible that they could have disabled javasripts. I doubt they would be using this section of the website using anything but desktop/laptops. This is a fairly small community of users who will be using this section of the website - e.g., members of an organization.
My original approach was to add a layer to the application, where upon submission, I would save their edits to a session array, and prompt them with a warning dialog. The methods responsible for displaying would use the values in the session array (if set), and they canceled, otherwise process them as normal. Avoiding that change, using the onsubmit event, is cleaner and wouldn't involve adding this layer to the 3 methods responsible for displaying/processing. When I started to post my original question, I was going to ask if the "road" I was headed down was a good road to "travel", but while writing thought of the alternate approach using client side confirmation.


Is there a way to use the onsubmit using server side code? Is there another way to do this without adding the layer? I like the idea of having the confirm dialog return true/false to the onsubmit. This is the way I normally would do things in a desktop application.

Thanks for your warning about javascript disabling.
Michael

Posted: Wed Apr 05, 2006 10:44 am
by Michael_C
timvw wrote:I find http://www.onlinetools.org/articles/uno ... pter1.html quite interesting. Basically, i don't have any javascript in my html markup but i attach it all when the script is loaded (actually, i attach when the document onload event occurs).
I'll take a look at the link. I can use all the help - I figure I have about a 30 % understanding of the object model et. al.- maybe, that's overestimated :wink:

Thanks for the pointer,
Michael