How to merge two identical jQuery scripts in one?
<p>Below there is a jQuery I use to add some entries in the DB. It is working correctly. I use the same one in the same file to remove some data. The form of the <em>remove-from-db</em> has id <code>RemoveMe</code> and it posts to <code>$.post("add-to-db.php?id=&lt;?php echo (int)$_GET['id'] ?&gt;"</code></p>

<p>Below you can see the <em>add-to-db</em> script with form id <code>AddMe</code>.</p>

<p>My question is if there is a way to make these two in one. Thank you.</p>

<pre><code>$(function(){
    $("#AddMe").submit(function(e){
       e.preventDefault();   
        $.post("add-to-db.php?id=&lt;?php echo (int)$_GET['id'] ?&gt;", $("#AddMe").serialize(), function (data){  
            $("#submit").attr('src','http://download.oracle.com/tech/blaf/specs/buttons/actnavbuttons/actnav_disabled_example.gif');
            $("#submit").attr('disabled',true);
            $("#submit").unbind('click');
            $("#message_post").html("Thank you");
setTimeout(function () { $("#message_post").hide(); window.location.href = "product.php?id=&lt;?php echo (int)$_GET['id'] ?&gt;"; }, 2000);

        });
    });
});

&lt;form id="AddMe"&gt;
&lt;input type="image" name="submit" id="submit" src="http://blog.mirthlab.com/wp-content/uploads/2008/04/rollover-up.png"&gt;
&lt;/form&gt;
&lt;div id="message_post"&gt;&lt;/div&gt;
</code></pre>

<hr>

<pre><code>$(function(){
    $("#RemoveMe").submit(function(e){
       e.preventDefault();   
        $.post("remove-from-db.php?id=&lt;?php echo (int)$_GET['id'] ?&gt;", $("#RemoveMe").serialize(), function (data){          
            $("#submit").attr('src','http://download.oracle.com/tech/blaf/specs/buttons/actnavbuttons/actnav_disabled_example.gif');
            $("#submit").attr('disabled',true);
            $("#submit").unbind('click');
            $("#message_post").html("Thank you");
setTimeout(function () { $("#message_post").hide(); window.location.href = "product.php?id=&lt;?php echo (int)$_GET['id'] ?&gt;"; }, 2000);
        });
    });
});

&lt;form id="RemoveMe"&gt;
&lt;input type="image" name="submit" id="submit" src="http://blog.mirthlab.com/wp-content/uploads/2008/04/rollover-up.png"&gt;
&lt;/form&gt;
&lt;div id="message_post"&gt;&lt;/div&gt;
</code></pre>
