Want to generate the random code when document load and refresh the code when refresh button click using javascript and jquery, also validate the random code please help...
Here is the form
<form class="custom-control custom-checkbox custom-control-inline">
<input id="test_code" class="" type="text" name="">
<label for="my-input" class="" id="captcha_code"></label>
<button type="button" class="btn btn-primary" id="submit">Test</button>
<button type="button" class="btn btn-primary" id="code_refresh" onclick="RefreshCode();">Refresh</button>
</form>
Here is the javascript code
<script>
var captcha;
var newCaptcha;
captcha = Math.floor((Math.random() * 10000) + 1);
$("#captcha_code").html(captcha);
function RefreshCode(newCaptcha){
newCaptcha = Math.floor((Math.random() * 10000) + 1);
$("#captcha_code").html(newCaptcha);
}
$("#submit").click(function (e) {
RefreshCode(newCaptcha);
var matchCode = $("#test_code").val();
if(matchCode == ""){
alert("Type Captcha Code");
return false;
}
else if(matchCode != code_refresh || (matchCode != captcha){
alert("Code Does not match");
return false;
}
});
</script>