# onClickToDial() for Salesforce Classic

## Usage

Registers a function to call when a user clicks an enabled phone number.

## Syntax

```javascript
sforce.interaction.cti.onClickToDial( listener:function )
```

## Arguments

| Name       | Type     | Description                                                   |
| ---------- | -------- | ------------------------------------------------------------- |
| `listener` | function | JavaScript method called when the user clicks a phone number. |

## Sample Code–JavaScript

```javascript
<html>
<head>
   <script type="text/javascript" src="http://domain:port/support/api/25.0/interaction.js"></script>
   <script type="text/javascript">
       var listener = function (response) {
           if (response.result) {
              alert('User clicked on a phone number.' + response.result );
           }
        };
   //Invokes API method
   sforce.interaction.cti.onClickToDial(listener);
</script>
</head>
</html>
```

## Response

This method is asynchronous. The response is returned in an object passed to a callback method. The response object contains the following fields.

| Name     | Type   | Description                                                                                                                                                                                                                                                                                                                                                             |
| -------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `result` | string | Returns the phone number, object ID, object name, and for API version 33.0 or later, the object tab name from where the click was initiated, as a JSON string. For API version 33.0 or later, invoking this method on a PersonAccount object also returns `accountId` or `contactId`, and `personAccount` (`true` if the object is a PersonAccount, `false` otherwise). |
| `error`  | string | If the API call was successful, this variable is undefined. If the API call failed, this variable returns an error message.                                                                                                                                                                                                                                             |

Example `result`:

```javascript
{"number":"4155551212","objectId":"001x0000003DIGj","objectName":"Account",
"displayName":"Company"}
```

Example `result` for a PersonAccount object (API version 33.0 and later):

```javascript
{"number":"4155551212","object Id":"001D000000JWVvP","objectName":"Howard Jones","object":"Account",
"personAccount":true,"contactId":" 003D000000QOBPX"}
```
