Can anyone help me put my 3 pieces of code together? I can run the script fine and it works I just dont know how to align this to a onclick button event
1) User clicks button.
2) Script is executed and sends message to API
IN HTML
<script src="jquery-git.js" type="text/javascript">
<script src='slackapi.js'></script>
Button to execute script
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Send Message</button>
</fieldset>
slackapi.js Script
var url = 'https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var text = 'This is a message'
$.ajax({
data: 'payload=' + JSON.stringify({
"text": text
}),
dataType: 'json',
processData: false,
type: 'POST',
url: url
});