开发者

preventDefault - not working as i expect

I have this code, and my idea is send the data to a validation.php but without submitting the form. The code bellow simple does nothing when clicked. My problem is, I can't permit the submit default action because when the button is pressed, it reloads to the initial page regardless the validation valid or not in PHP. If I change .click to .submit the same occurs, the page is reloaded.

 <script type="text/javascript" language="javascript">

   $(document).ready(function() {

      $("#customForm").click(function(event){
         event.preventDefault();
         $.post("validation.php", {
             nameRegist: $('#nameRegist').val(),
             emailRegist: $('#emailRegist').val(),
             myPasswordRegist: $('#myPasswordRegist').val(),
             pass2Regist: $('#pass2Regist').val()
         });
      });

   });
   </script>


<form method="post" id="customForm" action="">
            <div>
                <label for="name">Name</label> 
                <input id="nameRegist" name="nameRegist" ty开发者_开发知识库pe="text" /> 
                <span id="nameInfo">Insira o seu nome</span>
            </div>
            <div>
                <label for="email">E-mail</label> 
                <input id="emailRegist" name="emailRegist" type="text" /> 
                <span id="emailInfo">Insira um email válido por favor!</span>
            </div>
            <div>
                <label for="myPassword">Password</label> 
                <input id="myPasswordRegist" name="myPasswordRegist" type="password" /> 
                <span id="myPasswordInfo">Insira pelo menos 4 letras e sem espaços</span>
                <div id="bar" style="width: 234px; height: 20px;"></div>
            </div>
            <div>
                <label for="pass2">Confirm Password</label> 
                <input id="pass2Regist" name="pass2Regist" type="password" /> 
                <span id="pass2Info">Confirme a password</span>
            </div>
            <div></div>
            <div>
                <input id="send" name="send" type="submit" value="Send" />
            </div>
        </form>

http://emprego.xtreemhost.com/login/emprego.php - please click in the green button (registo) and then submit (sorry fot the bad server)


$(document).ready(function() {

      $("#customForm").submit(function(event){
         $.post("validation.php", {
             nameRegist: $('#nameRegist').val(),
             emailRegist: $('#emailRegist').val(),
             myPasswordRegist: $('#myPasswordRegist').val(),
             pass2Regist: $('#pass2Regist').val()
         });
         event.preventDefault();
         return false;
      });
   });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜