ajax form submit problem
ajax form submit problem
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script type="text/javascript" src="jquery-1.4.2.js"></script>
- <script>
- $(document).ready(function(){
- $('#form1').live('click',function(){
- $.post('submit.php', $('#form1').serialize(), function(data){
- $('#modalkast').empty().append('<br />'+data);
- $('#form1 input[type=text]').val('');
- $('#form1 input[type=password]').val('');
- $('#form1 input[type=textarea]').val('');
- $('#form1 input[type=checkbox]').removeAttr('checked');
- $('#form1 input[type=radio]').removeAttr('checked');
-
- });
- });
- });
- </script>
- <title>Untitled Document</title>
- </head>
- <body>
- <form action="#" method="post" id="form1">
- mingi tekst <input type="text" name="field" id="field" /><br />
- <input type="checkbox" name="field2" /> siin checkime<br /><br />
- <input type="button" value="send" />
- </form>
- <br /><br />
- <form action="olematu.php" method="post">
- <input type="text" name="kala" />
- <input type="submit" value="olematu" />
- </form>
- <div id="modalkast"></div>
- </body>
- </html>
the problem is that the form is submitted even when clicked on input text field or checkbox. how to fix it? and is there a better way to reset a form? also i would like all other forms act as normal ones!