How do I reload a form using javascript keeping results from a mysql query,
My Javascript; //reloads the form in Heredoc $MyHtml3
<Script type="text/javascript">
function reload(form) {
var cat = "<?php echo $category; ?>";
var catid = "<?php echo $catid; ?>";
var subcat = "<?php echo $subcat; ?>";
var subcat2 = "<?php echo $subcat2; ?>";
var subcatid= "<?php echo $subcatid; ?>";
var newfile= "<?php echo $newFile; ?>";
var fileclass=form.fileclass.options[form.fileclass.options.selectedIndex].value;
self.location='information.php?cat=' + catid + '&cat1=' + cat + '&subcat=' + subcat + '&subcat2=' + subcat2 + '&subcatid=' + subcatid + '&fileclass=' + fileclass + '&newfile=' + newfile ;
}
</script>
My HEREDOC HTML; //enables switching between $fileclass
$MyHtml3 = <<<EOD
<form method=post name=f1 action='information.php'>
<select name='fileclass' onchange="reload(this.form)" required><option value=''>Select one</option>
<option value="create">create</option>
<option value="modify">modify</option>
<option value="delete">delete</option>
</select><br><br>
</form>
EOD;
My PHP // that creates a table (the default fileclass 'create' works fine, but the modify and delete loose the mysql results)
<?php
echo $MyHtml3;
echo "<br>Forms Available in <b>" .$fileclass."</b>";
$ndir = $dir . $fileclass."/";
echo $ndir;
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($ndir));
echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"height: 44px; width: 100%;\">
<tbody>
<tr>
<td style=\"vertical-align: middle; width: 228px;\">Reference</td>
<td rowspan=\"1\" style=\"vertical-align: middle; width: 89px;\">Cerfa</td>
<td colspan=\"3\" rowspan=\"1\" style=\"vertical-align: middle; width: 595px;\">Name</td>
</tr>";
while($it->valid()) {
$fname = $it->getSubPathName();
//echo "the class is: ".$fileclass;
///start file ref query///
$quer2 = $dbo->prepare("SELECT form_id,form_description,form_name,form_cerfa
FROM form_detail
WHERE form_name = :form_name AND form_category = :form_category AND form_subcategory = :form_subcategory AND form_subcategory2 = :form_subcategory2 AND form_class = :form_class");
$quer2 ->bindParam(':form_name', $fname);
$quer2 ->bindParam(':form_category', $catid);
$quer2 ->bindParam(':form_subcategory', $subcatid);
$quer2 ->bindParam(':form_subcategory2', $subcat2);
$quer2 ->bindParam(':form_class', $fileclass);
$quer2 ->execute();
$result=$quer2->fetch(PDO::FETCH_OBJ);
///End file ref query ///
if ($result->form_cerfa==1) { $tmpCerfa = 'Yes'; } else { $tmpCerfa = 'No';} //works for create
if ($result->form_id=='') { $tmpID = 'Empty'; } else { $tmpID = $result->form_id;} //works for create
echo "this is the form id: " .$result->form_id;
if (!$it->isDot()) {
echo "<tr>
<td style=\"vertical-align: middle; width: 228px;\">".$tmpID."</td>
<td rowspan=\"1\" style=\"text-align: center; vertical-align: middle;\">".$tmpCerfa."</td>
<td colspan=\"3\" rowspan=\"1\" style=\"text-align: center; vertical-align: middle;\"><a href=".$ndir."/".$fname." target=\"_blank\">".$fname."</a></td></tr>";
}
$it->next();
}
echo '</tr></tbody></table>';
?>