You need to sign in to do that
Don't have an account?
Middha
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: VF Button
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
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?'); }
<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
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.
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;
}
}
}
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.
Regards
VIvek
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
This works fine if user selects false but if selects true, the complete page refreshes doing nothing.
Any other workaround on this??
GM
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
I am simply showing a confirm javascript on click of a commandlink which also rerenders some div. No formulas used.
Try this out this should work
Though adding it inline works, as you just said, i have used it in many places.
Thanks in advance....
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
if you are calling this function you are returning true if the user clicks oK!!.
Regards
Vivek