Saturday, 15 August 2015

javascript - Submit function not getting called when form is submitted -



javascript - Submit function not getting called when form is submitted -

the onsubmit tag not seem working. trying phone call submit() javascript function when submit button clicked on webpage. here code:

<!doctype html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="login.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script src="jquery.serializejson.min.js"></script> </head> <body> <script type="text/javascript"> function submit() { ....... } </script> <div class="login-container"> <div class="title">login form</div> <div class="form-fields"> <form name="login-form" id="login-form" onsubmit="return submit()"> <input type="text" name="username" id="username" placeholder="username" required></input> <input type="password" name="password" id="password" placeholder="password" required></input> <input type="submit" value="log in" id="submit-button"></input> </form> </div> </div> </body>

there naming conflict.

the form has native built in function can seen with

<form id="x" onsubmit="console.log(submit);"><input type="submit"/></form>

when @ console see

function submit() { [native code] }

so when phone call submit() calling native submit function aka document.getelementbyid("login-form").submit(); , not yours. around it, alter name.

change function name other submit.

function xsubmit(){ }

and

<form name="login-form" id="login-form" onsubmit="return xsubmit()">

javascript html forms

No comments:

Post a Comment