I'm shifting form #cart_form
from right column to left column after a button is hit.
And the code for that is:
$('#left_col').html($('#cart_form').html());
But I cannot submit it. I wondered if the code above properly copied all tags, right from <form>
to </form>
I checked if form
element exists, like this:
if ($('form').length == 0) {
alert("no");
}
And it doesn't alert 'no' meaning it exist. The markup for my form is,
<form action="#" method="POST" id="cart_form">
<table class='header_tbl' style="background:none !important;">
<thead>
<tr>
<th>Item Name</th>
<th>Unit Price</th>
<th>Qty</th>
<th>Amount(RM)</th>
<th></th>
</tr>
</thead>
.........................
CONTENT APPENDED BY JQueRY
........................
This button initiates the submission:
<input type='submit' name='submit' id='receipt' onclick='print_me()' value='PRINT RECEIPT'/>
And this is how it submit if cart is not empty.
function print_me(){
var ele = $(".header_tbl tbody tr").children().length;
if(ele > 0)
{
$("#cart_form").submit(function(){
var data = {
"action": "test"
};
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "submit_cart.php",
data: data,
success: function(data) {
alert(data);
}
});
});
}else
{
alert("Your cart is empty.");
}
}