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
shashi kanaparthishashi kanaparthi 

Showing the user an alert when a on click java script button is double clicked

Hi,

I am trying to show the user an alert message if the user has double clicked on a button. The button uses the java script code below. In order to do this, i created a checkbox field. I am updating it to true once the user clicks the button. Based on this, i am trying to show an alert. But the alert is not being shown to the user on the second click. I am also updating the checkbox to false, before navigating user to other page.

Let me know if this could be done with Java Script.

{!RequireScript("/soap/ajax/33.0/connection.js")}


var QuoteObj = new sforce.SObject("Quote");
QuoteObj.Id = '{!Quote.Id}';

var url = parent.location.href;


var OppId='{!Quote.Opportunity_ID_18_Char__c}'

var sync = '{!Quote.IsSyncing }'
var conversion = '{!Quote.Conversion_Status__c}'
var Q='{!Quote.Quote_CW__c}'

if( sync == false)
{
alert("Please sync your quote before continuing");
}
else if( conversion == 'Sent')
{
alert("Your Quote has already been sent to CW");
}
else
{
var r = confirm("Do not click the Quote to CW Button more than once.Note that you can only send Quote to CW one time. Are you sure you want to send? Once you click Ok, this page will redirect");

QuoteObj.Quote_CW__c = 'true';
var result = sforce.connection.update([QuoteObj]);


}


if(r==true)
{

var quoteID = '{!Quote.Id}'

postParams = {}
postParams.url = 'https://servicesuat.restorationhardware.com:10000/QuoteToCW/' + quoteID
postParams.method = 'GET'
postParams.requestHeaders = {}
postParams.requestData = ''
postParams.requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded' //or another mime-type
postParams.requestHeaders['Content-Length'] = postParams.requestData.length //required for POST
postParams.onSuccess = processSuccess
postParams.onError = processError
sforce.connection.remoteFunction(postParams)


function processSuccess(message)
{ do something with results¨
alert("Quote has been synced to CW, don't click the Quote>CW Button Again. This //page will now redirect");

if(Q=='true'){
alert("Don't click on the button again you have already clicked once");

}



QuoteObj.Quote_CW__c = 'false';
var result = sforce.connection.update([QuoteObj]);


parent.location.href= '/' + OppId;
}
function processError(message)
{ // do something with the error
alert('error');
}
}
Shashikant SharmaShashikant Sharma
Hi,

I think you are using a Deatil Button Executing Java Script.

First this way you can not count the clicks of a button. The reason is your count variable is getting initialized when user clicks on the button. Only thing you could do is to get the value of your CheckBox field and initialize with it but if user clicks it immidiately that case will not be handleled.

One way I could suggest is to have your Java Script Variable for click count to be decalred out side button java script. Like witha Home Page Component Java Script. So it gets loaded at the time of Deatil View Load and then you could increase it as user clicks on button.

See this: https://help.salesforce.com/HTViewHelpDoc?id=home_page_components_custom_vf_overview.htm&language=en_US

Let me know if you face any issues with it.

Thanks
Shashikant