Checking AJAX / Javascript checkbox

This is my first stackoverflow post, hope you can help me!

I need to have a javascript / ajax check for the checkbox in the form I create, the checkbox is canceled by default, but when it is checked, a javascript window appears displaying this text, "You selected the checkbox for the newsletter, you are sure you want to receive our newsletter ? " when they press the submit button.

If they click β€œyes”, the form should provide information about the newsletter for distribution, if not, the form should be submitted, but without information about the newsletter.

I am very grateful for the help, thanks.

+3
source share
1

SO!

Javascript, . , , , confirm(), . , Javascript, ​​ .

:

<script language="javascript">
        function checkNewsLetter()
        {
            var chk = document.getElementById('chk1');
            if ((chk.checked) && (!confirm('Are you sure you wish to sign up?')))
                chk.checked = false;
        }
</script>

<form onsubmit="return checkNewsLetter();">
        <input type="checkbox" id="chk1" name="chk1" />
        <input type="submit" />
</form>

jQuery JavaScript, .

+2

Source: https://habr.com/ru/post/1732180/


All Articles