function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MiddhaMiddha 

Javascript confirm before rerender

Hi,

I am using a command button on click of which an outputpanel gets rerendered. But i want user to confirm this before the panel gets refreshed.


Code: JS
function confirm()
{
 return window.confirm('Are you sure?');
}


Code: VF Button
<apex:commandButton id="clearS" rerender="detail"  onclick="return confirm();"  value="Clear" />

The problem is that is user selects yes, the complete page gets refreshed. But if i remove this confirm function, it only refreshes the ouputpanel itself.

Is there any way i can use confirm before rerendering a layer. Please advise.

GM

jwetzlerjwetzler
onclick="if(!confirm('Are you sure?')) return false;"

I think the ajax call is tacked on to the end of your onclick event so if you return early out of it, the ajax request will not being made.
Vivek ViswanathVivek Viswanath
I am trying to do this in my javascript I am trying to check a value qtyOverMax I am not getting the value in it rather I am getting the initially set value I put a call to a function in its get method but no use.
function save_clicked()
    {
    debugger;
    var saveNoIssuesValue = '{!qtyOverMax}'; // a value in the controller

        if (saveNoIssuesValue=="true")
            {
                input_box=confirm("Max Quantity is more than allowed. Click OK or Cancel to Continue");
                if (input_box==true)
                {
                    return true;
                }
        
                else if (input_box==false)
                {
                    // Cancel is clicked
                    return false;
         }
        }
               
    } 
jwetzlerjwetzler
Please reread my message.

The function you just posted always has a return type.  The function I posted does not.  Please fix your function to only return something (false) if cancel is clicked.
Vivek ViswanathVivek Viswanath
My issue is not that it returns it not reading the right value from the controller for the qtyOverMax

Regards

VIvek
jwetzlerjwetzler
You're getting the initial value because that formula is evaluated and injected into your script block when your page is loaded.  If you're not rerendering your script block after the value changes then that formula is not going to get re-evaluated. 
Vivek ViswanathVivek Viswanath
Thankz man I figured it out. Thankz to point out the direction

regards

Vivek


Message Edited by Vivek Viswanath on 08-05-2008 06:47 PM

Message Edited by Vivek Viswanath on 08-05-2008 07:02 PM
MiddhaMiddha
But my issue still remains, i tried as is suggested above and its not working for me. I am returning false and DONOT return anything if the value is true.

This works fine if user selects false but if selects true, the complete page refreshes doing nothing.

Any other workaround on this??

GM
Vivek ViswanathVivek Viswanath
Hi,

It would be good if you could post some code. Keep in mind you will have to put the javascript section that you are refrencing into a panel and refresh/rerender it before you call it so that the formula field is re-evavulated if you have a formula field. This is because the formula field is first evavulated on pageload and will get the latest value only on a re-render.


Regards

Vivek
MiddhaMiddha
My code is on top of this thread and i am not using any formula field. Actually 2 different topics got mixed in this thread.

I am simply showing a confirm javascript on click of a commandlink which also rerenders some div. No formulas used.
Vivek ViswanathVivek Viswanath
<apex:commandButton id="clearS" rerender="detail" onclick="if(!confirm('Are you sure?')) return false;"  action ='xyz' value="Clear" />

Try this out this should work
MiddhaMiddha
Thanks for replying Vivek. I have a complex, 20 line, logic for showing javascript confirm message. so i cant put the complete logic inline. Is there any other way that i can have the logic in JS method?

Though adding it inline works, as you just said, i have used it in many places.

Thanks in advance.... 
Vivek ViswanathVivek Viswanath
oh Ok

Here is my code have a look this code works as I am currently using it. Its very simple to understand I have a js code

<apex:outputPanel id="checkQTY" >
<script language="javascript">

    function save_clicked()
    {
    debugger; 
    var saveNoIssuesValue = '{!getData.qtyInsufficientOrOver}'; // formula field
        if (saveNoIssuesValue=="true")
            {
                input_box=confirm("The Total Revenue is less than the Minimum Required. This order will be sent to Field Services for Approval. Click OK to submit for approval, or Cancel to edit your order.");
                if (input_box==true)
                {
                      //returning nothing if ok is clicked
                }
       
                else if (input_box==false)
                {
                    // Cancel is clicked
                    return false;
                }
        }  
        }
</script>

</apex:outputPanel>

<apex:actionSupport event="onchange" action="{!calculateTotals}"rerender="checkQTY" /> // called inside an apex table is not required if you are not using a formula field.
//This is my command button

 <apex:commandButton value="Save and Create Order" onclick="return save_clicked();" action="{!SaveProgramOrderAndItems}"/>


let me know if this helps





Vivek ViswanathVivek Viswanath
BTW

function confirm()
{
return window.confirm('Are you sure?');
}

if you are calling this function you are returning true if the user clicks oK!!.

Regards

Vivek