// disable automatic opening of widget (scoring system)
callpage('api.scoring.toggle', false);
// this code should be placed into submit event handler of the form.
function submitHandler(e) {
e.preventDefault();
// get the input phone number from
var telFromForm = document.getElementById('myInput').value;
// event when the call is ordered. Use callback to get callRequestId
callpage('api.widget.call', {
tel: telFromForm
}, function(response) {
var callRequestId = response? response.id : null;
// it means that we successfully ordered a call
if (callRequestId) {
console.log("Unique call ID: " + callRequestId);
// start count down on HTML element #countdown, element should have 2 childs with selectors .cp-countdown__seconds and .cp-countdown__miliseconds
callpage(
// name of function
'api.countdown.start',
// element selector
'#countdown',
// on start callback
function() {
callpage.jQuery('#countdown')[0].style.display = "block";
},
// on end callback
function() {
callpage.jQuery('#countdown')[0].style.display = "none";
callpage.jQuery('#result')[0].style.display = "block";
}
);
}
else {
// put here any logic if call was unsuccessful (e.g. no managers available, or after hours)
}
});
}
document.getElementById('form').addEventListener("submit", submitHandler);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.