when using jquery to change the div content the form action in the div taking to the main page
<p>I am using jquery to change my div contents in the main.php file without refreshing the page,
but issue here is in the new div which is loaded contains a form, in the form action i want the form to be submitted to the same page(div) , but am redirected to the main.php which i don't want. What changes i have to make to the action to stay on the same page with the same div.</p>

<p>This is the code which i use to dynamically change the div.</p>

<p>main.php:</p>

<pre><code>&lt;li id="nav-home"&gt;&lt;a class="button" href="main.php"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li id="nav-page1"&gt;&lt;a class="button" href="page1.php"&gt;Page1&lt;/a&gt;&lt;/li&gt;    
&lt;li id="nav-page2"&gt;&lt;a class="button" href="page2.php"&gt;Page2&lt;/a&gt;&lt;/li&gt;
&lt;li id="nav-page3"&gt;&lt;a class="button" href="page3.php"&gt;Page3&lt;/a&gt;&lt;/li&gt;

&lt;script&gt;
    $(function(){
        $('.button').on('click', function(e){
            e.preventDefault();
            $('#content').load($(this).attr('href'));
        });
    })
&lt;/script&gt;
</code></pre>

<p>example: when i click on the Page1 in the main.php the div content is being replace by the page1 where in page1 i have a form, when i submit the form i want to stay in the same page.</p>

<p>this is the code which handles the form in the page1:</p>

<pre><code>&lt;form name="form" id="form" method="POST" action=""&gt; //my form elements &lt;/form&gt;

    &lt;script type="text/javascript"&gt;
        $(document).ready(function(){
            $("#form").validate({
                debug: false,
                rules: {

                    //rules
                },
                messages: {

                    //messages
                },
                submitHandler: function(form) {
                    // do other stuff for a valid form
                    $.post('scripts/formhandler.php', $("#form").serialize(), function(data) {
                        $('#results').html(data);
                    });
                }
            });
    });
    &lt;/script&gt;
</code></pre>
