Control whether data is submitted by using the Onsibmit of the form
The return values are true commits, others are unchanged, examples are as follows:
JS section
function Check () {varNewpwd = document.getElementById ("newpwd"); varConfirmnewpwd = document.getElementById ("confirmnewpwd"); if(Newpwd.value = =confirmnewpwd.value)return true; Else { varErr = document.getElementById ("errmsg"); Err.style.display=""; return false; } }
Html
<form action="/student/updatepwd"onsubmit="return check ()"> <divclass="Control-group"> <labelclass="Control-label" for="Basicinput"> Old password </label> <divclass="Controls"> <input placeholder="Please enter ..."data-original-title="" class="span8 Tip"Type="Password"Name="oldpwd"Id="oldpwd"> </div> </div> <divclass="Control-group"> <labelclass="Control-label" for="Basicinput"> New Password </label> <divclass="Controls"> <input placeholder="Please enter ..."data-original-title="" class="span8 Tip"Type="Password"Name="newpwd"Id="newpwd"> <spanclass="Help-inline"style="Color:red;display:none"Id="errmsg"> two times password inconsistency </span> </div> </div> <divclass="Control-group"> <labelclass="Control-label" for="Basicinput"> re-enter new password </label> <divclass="Controls"> <input placeholder="Please enter ..."data-original-title="" class="span8 Tip"Type="Password"Id="confirmnewpwd"> </div> </div> <divclass="Control-group"> <divclass="Controls"> <button type="Submit" class="Btn-inverse Btn-large"> Updates </button> </div> </div> </form>
HTML JS Form pre-submission detection data