Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138221

Want to generate the random code when document load and click refresh button using javascript and jquery and and validate the code

$
0
0

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>

Viewing all articles
Browse latest Browse all 138221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>