Submit within submit not working
Hello,
I'm a new user to jQuery. I was able to read data from a form and submit it using jQuery and return results in a table using JSON. (Image 1).
The code that processes it is as follows:
function submitSearch2(formid, ajax)
{
formid = "#" + formid;
ajax = "span." + ajax;
jQuery(document).ready
(
function()
{
jQuery(formid).submit
(
function()
{
jQuery.post
(
"_update.php",
jQuery(formid).serialize(),
function(data)
{
jQuery(ajax).html(data.message);
},
"json"
);
}
);
}
);
}
The page does not refresh. When my results return, it looks like this. (Image 2).
But when I get the list of results, and click on Add to List at the bottom, it doesn't process!
Here's the php code which is called from jQuery:
$upc = $_POST['upc'];
$format = $_POST['format'];
$asin = $_POST['asin'];
$title = $_POST['itemtitle'];
$xml = new Xml();
$products = $xml->getProductInfo($upc, $format, $asin, $title);
$html .= "<form name=\"results\" id=\"results\" onsubmit=\"return false;\">
<input type=hidden name=\"request\" value=\"addItemsToList\" />
<table border=\"1\">
<thead>
<tr>
<th>Product ID</th>
<th>UPC</th>
<th>Format</th>
<th>Title</th>
<th>ASIN</th>
<th>Image</th>
<th>Include</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>";
for($i = 0; $i < count($products); $i++)
{
$html .= "<tr>
<td>{$products['productid'][$i]}</td>
<td>{$products['upc'][$i]}</td>
<td>{$products['format'][$i]}</td>
<td>{$products['title'][$i]}</td>
<td>{$products['asin'][$i]}</td>
<td><a href=\"http://....jpg\"><img border=\"0\" src=\"http://....jpg\" /></a></td>
<td><div align=\"center\"><input type=\"checkbox\" name=\"include\" id=\"include\"/></div></td>
<td><input type=\"text\" name=\"quantity\" id=\"quantity\" size=\"5\" /></td>
</tr>";
}
$html .= "</tbody></table></form>";
$html .= "<div align=\"center\"><a href=\"javascript:submitSearch2('results', 'ajax_addItems')\">Add to List</a></div>";
$html .= "<span class=\"ajax_addItems\"></span>";
session_start();
session_regenerate_id();
$id = session_id();
$json = array(message => $html);
echo json_encode($json);
Thanks,