HTML file:
<html>
<body>
<main>
<div class="form-row">
<div class="form-group col-md-6">
<input type="email" class="form-control" id="inputEmail">
</div>
</div>
<button onclick="unsubscribe()" type="button">Unsubscribe</button>
</main>
<script src="js/unsubscribe.js" type="text/javascript"></script>
</body>
</html>
unsubscribe.js content:
function unsubscribe() {
var email=document.getElementById("inputEmail").value;
var requestOptions = {
method: 'POST',
redirect: 'follow'
};
fetch("https://apilink/"+email)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('Error!', error));
}
I'm not sure why the function is returned as undefined when I've defined it in the external js file and linked the js file in the html body.