I'm working on a project where when a user enters 13 characters in the input, then the form gets submitted automatically using JavaScript without pressing a submitted button.
Now i want to add a beep sound when the user enters the 13th character in the input.
<input id="text" type="text" maxlength="13" class="form-control" value='' name="order_id" autofocus>
function play() {
var audio = new Audio('beep.mp3');
audio.play();
}
$("#text").keyup(function(e) {
var length = this.value.length;
if (length == 13) {
play(); //first i need to run this function to play sound then i want to submit form after 1.5 second
this.form.submit();
e.preventDefault();
}
});
})
setTimeout.play()method after playing the audio or usesetTimeout