I have a form on my page, the user has the option to select from the dropdown and then click a 'Log' button.
On the click I want my JS to run and pass the value selected through into the payload for my slack webhook.
i.e. If option 3 was select and the user clicks 'Log'
var text = [Answered – not oncall – assisted with issue]
HTML
Select Options
<select name="option" id="option_id">
<option value="1">[No number listed]</option>
<option value="2">[Not answered]</option>
<option value="3">[Answered – not oncall – assisted with issue]</option>
<option value="4">[Answered – not oncall – unavailable]</option>
<option value="5">[Answered – oncall - unavailable]</option>
<option value="6">[Answered – oncall - available]</option>
</select>
Button
<button name="Log" type="submit" id="Log-submit" data-submit="...Sending">Log</button>
JS
$(document).ready(function() {
$('#Log-submit').on('click', function(e) {
e.preventDefault();
var btn = $(e.target);
btn.attr("disabled", "disabled"); // disable button
var url = 'https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var text = // My Option that I selected goes here
$.ajax({
data: 'payload=' + JSON.stringify({
"text": text
}),
dataType: 'json',
processData: false,
type: 'POST',
url: url
});
});
});