Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

submit button with javascript confirmation

by greenFox (Vicar)
on Aug 15, 2002 at 06:39 UTC ( #190323=snippet: print w/ replies, xml ) Need Help??

Description: Not 100% perl but it took me *ages* to work it out and I couldn't find any examples any-where so I wanted to make a record for the next poor schmuck. If you press the button created it will pop up a window prompting you with OK or cancel. Hitting OK will submit the form, hitting cancel will not. The CGI.pm doco for submit says you cannot stop the form from being submitted with an onClick action but I tried it with Mozilla 1.0 and IE 5 and the form wasn't submitted in either case...
print $cgi->submit(
    -name    => 'delete',
    -value   => 'Delete User',
    -onClick => 'return confirm("Delete account?")',
);
Comment on submit button with javascript confirmation
Download Code
Re: submit button with javascript confirmation
by simon.proctor (Vicar) on Aug 15, 2002 at 08:08 UTC
    Its probably not much but as a matter of personal javascript style I would have suggested that you create an ordinary button rather than submit button and put the click handler on that.

    Again thats only a matter of personal taste but my personal opinion is that if you are going to override the submit functionality then you should really not use a submit button.

    YMMV but I've found that approach to be the least error prone, especically as not everyone has IE5 as a base minimum (Linux and Macs anyone?). Of course, you absolutely must have the button in a Form otherwise you can forget it in Netscape.

    Still, better yet, why not just put a confirmation screen in your CGI for those with javascript turned off?

      I take your point, in this instance though the target environment has a strictly controlled SOE with IE5 with javascript turned on and I was told to make the user feedback java alerts... I didn't mention it because I was trying to stay out of the javascript debate :)

      What do you mean by an "ordinary button"? I still need to submit the form if the user hits OK on the java confirm popup, how else would I do that?

      --
      Until you've lost your reputation, you never realize what a burden it was or what freedom really is. -Margaret Mitchell

        you could always have a button that would go to a function and basically submit the form if the user clicked ok on the confirmation message. i.e.
        <input type="button" name="submit" value="javascript: submitForm();"> <script language="javascript"> function submitForm() { if (confirm("delete account?")) { mainForm.submit(); } } </script>
        this wasn't a very perl-y example.. but it's similar to what simon.proctor suggested.
Reaped: Re: submit button with javascript confirmation
by NodeReaper (Curate) on Sep 27, 2012 at 06:40 UTC
Reaped: Re: submit button with javascript confirmation
by NodeReaper (Curate) on Jun 28, 2013 at 20:32 UTC

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://190323]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-12-28 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls