Welcome Guest, Not a member yet? Register   Sign In
Need form submit help
#1

[eluser]nandish[/eluser]
trying to validate before form submit, its validating and giving alert message ,its not stoping form submit at all

Thanks

Code:
function validateLogin() {
if (!Checkvaliduser())
{
    return false;
}
}

//--------------------------------------------------------
function Checkvaliduser(){
    var userID = $("#userid").val();
    var passwordvalue = $("#password").val();
   if($.trim(userID)!= "" && $.trim(passwordvalue)!= ""){
                var checkUser=true;

       $.get("/index.php/clogon/verifyLogin/" + userID + "/" + passwordvalue,function(data) {
                   if(data.toString() == "0") {
                       checkUser = false;
                }
       });

            if(!checkUser) {  
                 alert("Invalid User ID and Password");
                      $("#userid").focus();
                       return false;
            }
return checkUser;
}
}

Edited by Michael Wales: Removed the coloring, added code tags.
#2

[eluser]Evil Wizard[/eluser]
I assume that is JavaScript?

Using something like jquery to overwrite and hook into the form submit event
Code:
$(document).ready(function () {
    $('#form_id').submit( function () {
                 if(validateLogin()) {
                        $('#form_id').submit();
                 };
                 return false;
        });
forcing the submit to return false all the time prevents the form from being submitted except by execution of code.




Theme © iAndrew 2016 - Forum software by © MyBB