0

I'm looking for the best way to go about "forcing" the user to fill a textarea.

For my work we have a system that keeps track of time spent on a particular "task". Some tasks are required to have a comment while others are optional. At the top of the page there is a timer, a textarea for the comments and a list of different tasks.

So far I have it so when the user tries to stop the timer, it won't stop until the comment is written (if it is required). When the paged is closed while the timer is running, an onbeforeunload function sends an alert warning that the comments aren't filled out and then the "Are you sure you want to leave?" warning pops up.

As far as I can tell there is no way to prevent the user from completely exiting the page. The idea we had was when the user closes the window, have another simple page open that just has a textarea and an instruction telling the user to write a comment. I'm pretty new to JavaScript and web development so I'm not entirely sure the best way to go about this.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Kashi
  • 25
  • 4
  • what will happen if user shut down the system. – zod May 31 '11 at 20:35
  • Right now the default if the browser is closed if the timer is still running is the unload event will save the time and entry so no data is lost. I also have 2 pop-ups (since I can't seem to alter the text for the "Are you sure you wish to leave this page?" warning) triggered by the onbeforeunload event that tell the user to stop the timer. If the system shut down and those events were not triggered then any time on the timer would be lost. – Kashi May 31 '11 at 20:51

2 Answers2

0

There is no way to prevent the user from leaving a page.

Built in pop up blockers will also block the system from opening up popup windows onunload. Only way to allow onunload popups is if your system admins can update every browser to add an exception to the browser security settings.

It is impossible to make a web application act like a client application.

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • I understand that there is no way to prevent a user from leaving a page, and I'm thankful for it, but I'm just looking for the best way to ensure that the text area is filled out if it is required. Also, only the people in my company are going to be using this page so less than 20 people. Like I said I have those pop-ups warning the user if the comments are blank but I'm not sure if there is a better or safer way. Thanks for the fast response. – Kashi May 31 '11 at 18:43
0

Put that text area in a popup or iframe or modal window where you can control its closing.

On these window.close you can call the functions to validate the text area is filled or not.

Am not sure you can put that in a popup or not .but thats the only good way i can think of !!

zod
  • 12,092
  • 24
  • 70
  • 106
  • @kashi if anything good happen you should start learning to add points or accept answers.good luck :-) – zod May 31 '11 at 21:14