How to use CRM custom button and client script?

How to use CRM custom button and client script?

Here's what I need.

I know how to handle each step in isolation.

I do not understand how to intercept a Button interaction, pass it to the client-script for the user prompt, and remainder of the processing.

  1. User Clicks Button on Details Page
  2. Client-Side Code fetches the value of a field.
  3. If value is X, prompt user Yes or No
  4. If Yes, set a field value which triggers a Workflow
  5. If No, do nothing.