For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > July 2005 > Re: [PEAR] QF: javascript confirm on submit









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] QF: javascript confirm on submit
Graham Clarke

2005-07-25, 5:32 pm

I use return & confirm like this

array('onclick'=>'return confirm('Are you sure it is OK to Delete?')')

hth

Graham


PitesaJ@peteramayer.com wrote:
> I need to put a javascript confirm() on submit. If I use:
>
> $g_buttons[] = & HTML_QuickForm::createElement('submit','
btnSubmit',
> 'Submit', array('onclick'=>'goConfirm()'));
>
> function goConfirm() {
> var answer = confirm ("Are you sure it is OK to Delete?")
> if (!answer)
> window.location="menu_redirect.php"
> }
>
> Then no matter if "OK" or "Cancel" the form is submitted.
>
> If I change the input element from submit to button as follows:
>
> $g_buttons[] = & HTML_QuickForm::createElement('button','
action',
> 'Submit', array('onclick'=>'goConfirm()'));
>
> and change the javascript to:
>
> function goConfirm() {
> var answer = confirm ("Are you sure it is OK to Delete?")
> if (!answer){
> window.location="menu_redirect.php"
> } else {
> document.frmPubEdit.submit();
> }
> }
>
> It works. However, per the documentation
>
>
> We don't need values from button-type elements (except submit)
>
> Well I do. I have several submit buttons on the page which submits the
> data then directs you to another specific QF and then back. Since there
> is not a value assigned to the button I cannot trap when this button is
> clicked. A nested if statement eliminating the values of the other
> buttons works in most cases but not this particular form (which leads to
> another post).
>
> Is there a better way to get the confirm message to work or can I assign a
> value to a button even if it was not anticipated necessary?
>
>


--
Graham Clarke
grahamc@53tech.com
www.53tech.com
603.643.9955
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com