I have created an input box and it gets validated by tab key. But it needs to be validated when the enter button is to be pressed.
function checktxt(h, v, w, c) {
var th = $("#" + h).val();
var tv = $("#" + v).val();
if (th.toLowerCase() == tv.toLowerCase()) {
$("." + c).show();
$("." + w).hide();
var win = new Audio('audio/wright.mp3');
} else if (tv.toLowerCase() == "") {
} else {
$("." + c).hide();
$("." + w).show();
//setTimeout(function() { $( "."+w ).hide(); }, 5000);
var win = new Audio('audio/wrong.mp3');
}
win.play();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="position:absolute; margin-left:350px;top:226px;">
<input id="texthidden1" type="hidden" value="413" />
<input id="textvisible1" type="text" value="" style="font-size:32px;text-align:center;border:0px solid black;height:50px;width:100px;" maxlength="4" onblur="javascript:checktxt('texthidden1','textvisible1','wrong1','correct1');" />
<div class="wrong1" style="margin-left: 120px;margin-top: -30px; position:absolute; float:left; display: none; margin-bottom:-30px; ">
<img src="../images/smallwrong.png" />
</div>
<div class="correct1" style="position:absolute;margin-left: 120px; margin-top: -30px; float:left; display: none; margin-bottom:-30px;">
<img src="../images/smallgreen.png" />
</div>
</div>
You can perform the validation when you detect the enter key is pressed.
$(document).keypress(function(e) {
if(e.which == 13) {
// enter pressed now validate
checktxt(h,v,w,c)
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With