javascript - Not able to submit the form using jquery -
hi have login form page validated using jquery. jquery script checking null values when entered values not submittingbut able see alerts in else block
<script type="text/javascript"> $(document).ready(function(){ $("#submit").click(function(){ //$(this).hide(); var name = $.trim($("#uname").val()); var pwd = $.trim($("#pwd").val()); alert("value: " + name); alert("text: " + pwd); if(name == ''){ alert('ssss'); $(":input").css({ "background-color":"#ffcece", "border":"1px solid red" }); // homecoming false; $('form').submit(function(){ //e.preventdefault(); homecoming false; }); }else{ alert('else'); $(":input").css({ "background-color":"", "border":"" }); alert('else2'); $('form').submit(function(){ alert("thanks"); homecoming true; }); alert('else3'); } }); }); </script>
this html code
<form action="" method="post" name="loginform"> <table> <tr> <th>login page</th> </tr> <tr> <td>name</td> <td><input type="text" name="uname" id="uname" /></td> <tr> <tr> <td>password</td> <td><input type="password" name="pwd" id="pwd" /></td> <tr> <tr> <td colspan="2"><input type="submit" name="submit" id="submit" value="submit" /> </td> <tr> </table> </form>
thanks in advance..
instead of
$('form').submit(function(){ alert("thanks"); homecoming true; });
in else, return true;
same in if, don't need
$('form').submit(function(){ //e.preventdefault(); homecoming false; });
just return true;
what you're doing in code hooking submit event of form. if homecoming false or true submit button, it'll submit form or not.
javascript jquery
No comments:
Post a Comment