Forum Moderators: coopster & phranque

Message Too Old, No Replies

when a user clicks ok on dialog box how do I pass that to perl code?

         

mr_evans2u

9:39 pm on Mar 27, 2003 (gmt 0)

10+ Year Member



I've got a subroutine in perl that will remove a "lock" on a file. When I use a submit button for this it works great.
I also have a javascript function that brings up a dialog box when the user tries to navigate from the page. What I don't know how to do is make these two actions talk to each other when the user clicks the ok button to navigate away from the current page.
Can this be done?

####perl/cgi####
@checked = param('checkbox');
($uid, $pass) = sieve_util_remove_filter($relay, $relay_dir, $filename, $home_dir, @checked);

###html####
print start_html(-title=>"Sieve Filter Administration",
-script=>{-language=>'javascript',
-src=>'load.js'},
-onbeforeunload=>"closeIt()",
-background=> "gray.jpg"),

####.js######
function closeIt()
{
event.returnValue ="_______________________________________________________ \n\n"+
"Leaving without saving will cause loss of any new or modified data.\n" +
"_______________________________________________________ \n\n"

}

jatar_k

4:45 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld mr_evans2u,

since this was just moved in here I figured a bump would get the perl folks' attention. ;)

Though couldn't you just post it from the dialog to a script and refresh the main window page?

toadhall

6:30 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



If I'm right in assuming you want to make sure the visitor knows the consequences of leaving, and is also given an opportunity to turn back, have you considered using the confirm() [oreillynet.com] Method in the closeIt() function?

It renders "OK" and "Cancel" buttons with your message that return 'true' or 'false' values.

Hope I'm reading your problem correctly.

T

mr_evans2u

7:03 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



that part of it works already. The dialog box pops up like it is suppose to. But when the user clicks "ok" I don't know how to call the perl code to clear the lock on that file so that other users will be able to access it.

toadhall

8:33 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



> when the user clicks "ok" (in the alert/confirm window)

...to run the cgi...

function closeIt(){
var msg="your_message";
if (confirm(msg) {
location.replace(path_to_cgi)
} else {
location.replace(path_to_elsewhere)
}
}

-or-

function closeIt(){
var msg=window.confirm("your_message");
if (msg==true){
window.location="path_to_cgi";
}
}

...in this second case a click on Cancel leaves them on the original page, OK runs the cgi.

Are we getting close?

T

DrDoc

8:55 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And what happens if the user just closes the browser? How will the lock be removed then?

toadhall

9:26 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



Right. A blowtorch wouldn't do in that case.

(Perl 101 says: "...collect the data, flock / write / get the flock outta there.")

T

mr_evans2u

9:36 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



yeah, that is the basic idea that I'm going for. I will see if I can get your idea to work, thanks. As far as the user just closing the browser: the dialog box still gets poped up before it allows the browser to close.

DrDoc

10:22 pm on Mar 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As far as the user just closing the browser: the dialog box still gets poped up before it allows the browser to close.

And if they have disabled JavaScript? (and don't say "they won't be able to reach the page without having JS enabled"... since they can disable it after loading the page)

Flock the file and do whatever you need to do, but release the flock before loading the page.

'cause, what happens if the computer crashes, or the user does Ctrl-Alt-Del to get out of the page...

The flock must be released before the page is loaded, or, not flocked at all until the user navigates away.

mr_evans2u

10:39 pm on Mar 28, 2003 (gmt 0)

10+ Year Member



well I can't say they won't, but I hope since this for administrators that are suppose to read the release notes prior to signing off on this project they will know that they are not to disable javascript, but I completely understand your concern.

Thanks