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
nelloCnelloC 

window.confirm not working

Don't know when this stopped working but it was working and now not. I have the following code:

apex:tab label="Contacts" name="contactList">
<apex:pageBlock title="Contacts" id="contact_list">
<apex:pageBlockTable value="{!RelatedContactsList}" var="CO">
<apex:column headerValue="Action">
<apex:commandLink action="{!DeleteDLContact}" reRender="contact_list" onclick="window.confirm('Are you sure?');">
<b>Del</b>
<apex:param name="dlcontactid" value="{!CO.Id}" assignTo="{!DeleteDLContactID}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!CO.Contact__r.LastName}, {!CO.Contact__r.FirstName}" headerValue="Name"/>
<apex:column value="{!CO.Contact__c}"/>
<apex:column value="{!CO.Contact__r.Email}"/>
<apex:column value="{!CO.Contact__r.AccountId}"/>
</apex:pageBlockTable>
<apex:outputLink value="/apex/DistributionListContacts?dl={!id}" rendered="{!ContactListHasMore}">Show more »</apex:outputLink>
</apex:pageBlock>
</apex:tab>

When "Del" link is clicked the action method "DeleteDLContact" is called not matter whether OK or Cancel is clicked on the "Are you sure?" confirmation.

I have tried changing the onclick to onclick="return window.confirm('Are you sure?');"  but this results in the action method not being called at all. This definately was working, I can't work out what has changed to stop it working.

 

Any ideas? Thanks.

Message Edited by nelloC on 12-13-2009 03:57 AM
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

There's some hits on google about onclick not behaving correctly under vista.

 

It may be that the return is confusing the browser (although it shouldn't).  Try changing your onclick handler to only return a value if the confirm returns false.  Something like:

 

if (!window.confirm('Are you sure?')) return false; 

All Answers

bob_buzzardbob_buzzard

There's some hits on google about onclick not behaving correctly under vista.

 

It may be that the return is confusing the browser (although it shouldn't).  Try changing your onclick handler to only return a value if the confirm returns false.  Something like:

 

if (!window.confirm('Are you sure?')) return false; 

This was selected as the best answer
nelloCnelloC

I use Firefox for development and it was working... (yes, I'm beginning to doubt myself now!) it's always disconcerting when something changes without knowing the what and why. But your suggestion works perfectly, thanks for that Bob.