javascript - How to redirect if form submission is successful and remains on the page its false using js -


here code. want redirect page after successful form submission , remains on page , user needs fix error

<form id="form_1" name="form" action="#" method="post">   <div class="btn-group" data-toggle="buttons">     <input class="radio_btn" type="radio" name="group1" value="true">yes     <input class="radio_btn" type="radio" name="group1" value="false">no   </div>   <div class="btn-group" data-toggle="buttons">     <input class="radio_btn" type="radio" name="group2" value="true">yes     <input class="radio_btn" type="radio" name="group2" value="false">no   </div>   <button type="submit">submit</button> </form>  <script>   var form = document.queryselector('#form_1');   var radiolist = form.queryselectorall('.radio_btn');   form.addeventlistener('submit', function() {     (var = 0, length1 = radiolist.length; < length1; i++) {       if (radiolist[i].getattribute('value') == 'false' && radiolist[i].checked) {         alert("error");         return false;       } else {         return true;         window.location.assign("http://worldlivecricket.com");       }     }   }); </script> 

you can using jquery

$("#form_1").on("submit",function(e){    if(your validation) {       // redirect     } else {       e.preventdefault();    } }); 

here e.preventdefault(); stop page reloading


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -