You should use unobtrusive event listeners, as opposed to inline JS:
<button id="headphone">headphone detected?</button>
function detectHeadphones(){
window.plugins.headsetdetection.detect(function(detected){
if(!detected){
//No headphone detected
alert("No headphone detected");
// Set your variables here
}
})
};
var headphoneButton = document.getElementById("headphoneButton");
headphoneButton.addEventListener('click', detectHeadphones);
Then you can check detected for a falsey value thus: if(!detected){
and set whichever variables you need within the callback. These variables will need to have been defined in a way that they are in scope at this point.