2017-07-28 76 views
0

這是我的代碼。我想成功的表單提交後的重定向頁面,它仍然在該網頁上,並且用戶需要修復錯誤如何重定向表單提交是否成功,並保留在頁面上它的假使用js

<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() { 
    for (var i = 0, length1 = radioList.length; i < 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> 

回答

0

您可以使用jquery

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

這裏e.preventDefault();將停止做這樣的重新加載頁面

相關問題