Good day.

The question is quite noobish, but I ask for help, since JS has just started to learn, and jQuery has not yet penetrated at all.

There is a page with ready validation of inputs (radio) on whether they are selected or not. If no answer is selected, the default button is disabled and the text Please, give answers to all questions . If selected, move on.

But validation works generally on the page.

It is necessary to alter it somehow, so that when you click on the submit button, validation check starts. If everything is ok, we’ll start action="http://google.com" , if not, we span.warning-text show a message from span.warning-text . Well, no disabled on the button to use already.

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <!-- RADIO SELECTION VALIDATION SCRIPT--> <script type="text/javascript"> var a01 = $('input[name=answer-1]'); var a02 = $('input[name=answer-2]'); var a03 = $('input[name=answer-3]'); var a04 = $('input[name=answer-4]'); var a05 = $('input[name=answer-5]'); validate(); $("input[type='radio']").change(validate); function validate() { if ($(a01).is(':checked') && $(a02).is(':checked') && $(a03).is(':checked')&& $(a04).is(':checked')&& $(a05).is(':checked')) { $(".btn#submit").removeAttr("disabled", false); $(".warning-result-text").css("opacity", '0'); } else { $(".btn#submit").attr("disabled", true); } } </script> 
 <form class="get-result-form" action="http://google.com"> <span class="warning-text">Please, give answers to all questions</span> <input class="btn btn-submit" id="submit" type="submit" value="Submit answers" disabled="true"> </form> 

    2 answers 2

    Validation should be checked on php or js client language and it is easier to fool it by sending data to the server and checking there if everything is ok, it will be transferred further, if not, it will transfer you to the same page and report error.

    • I would be very grateful if you tell me how to implement this using PHP. - desmond
    • you send $_POST to the file where the check will take you take the necessary imput for example ( $_POST['Language'] ) and in if you check then you throw the header where it is necessary, if for example we give a wrong session and from this session you go to the same page where you sent the request through the session you make an error again through checking - Gotha

    In general, I decided this question like this:

     $('.get-result-form').submit(function valForm() { var a01 = $('input[name=answer-1]'); var a02 = $('input[name=answer-2]'); var a03 = $('input[name=answer-3]'); var a04 = $('input[name=answer-4]'); var a05 = $('input[name=answer-5]'); validate(); $("input[type='radio']").change(validate); function validate() { if ($(a01).is(':checked') && $(a02).is(':checked') && $(a03).is(':checked')&& $(a04).is(':checked')&& $(a05).is(':checked')) { this.submit(); } else { $(".warning-result-text").css("opacity", '1'); event.preventDefault(); } } });