javascript - Loading a html table with PHP via a JQuery .load call -
aim
i trying create page delete records database.the page consists of populates upon page load.upon selecting value , clicking submit button, php page called , results of php loaded table below .i can click on delete button beside values echoed delete value database
my form:
<!doctype html> <html> <head> <!--loads jquery script--> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <!--gets list of item categories on page load--> <script type="text/javascript"> $(document).ready(function(){ $("#viewsubcat").load("getcategory.php"); }); </script> <script type="text/javascript"> $("#viewsubcatsubmit").click(function(){ var cat=$('#viewsubcat').val(); $('#deletetable').load('delsubcategory.php?cat='+cat); }); </script> </head> <body> <form style="width:500px" id="viewsubcategory" name="viewsubcategory" method="post" action="<? php echo $_server['php_self'] ?>" > <div class="inputfield"> <label for="viewsubcat">select category:</label> <select style="margin-left:37px" id="viewsubcat" name="viewsubcat"></select> </div><br /> <div class="inputfield"> <input style="margin-left:250px" type="button" id="viewsubcatsubmit" name="viewsubcatsubmit" value="search" /></div> </div><br /> </form> <table id="deletetable"> </table> </body> </html>
php page:
<?php include("cxn.inc"); $id=$_session['bizid']; $cat=$_get['cat']; $viewsubcat=$cxn->prepare("select * `itemcat`,`itemsubcat` `itemcat`.`catid`=:cat , `itemsubcat`.`itemcat`=:cat , `itemsubcat`.`businessid`=:id"); $viewsubcat->bindvalue(":cat",$cat); $viewsubcat->bindvalue(":id",$id); $viewsubcat->execute(); //echo"<table border='1'>"; echo"<tr>"; echo"<td>"; echo"categories"; echo"</td>"; echo"<td>"; echo"subcategories"; echo"</td>"; echo"<td>"; echo"action"; echo"</td>"; echo"</tr>"; while($getsubcat=$viewsubcat->fetch(pdo::fetch_assoc)) { $cat=$getsubcat['itemcat']; $subcat=$getsubcat['itemsubcat']; $subcatid=$getsubcat['subcatid']; echo"<tr>"; echo"<td>"; echo"$cat"; echo"</td>"; echo"<td>"; echo"$subcat"; echo"</td>"; echo"<td>"; echo"<form id='delsubcategory' name='delsubcategory' method='post' action='delsubcategory.php'>"; echo"<input type='hidden' id='delsubcatid' name='delsubcatid' value='$subcatid' />"; echo"<input type='submit' id='delsubcatsubmit' name='delsubcatsubmit' value='delete' />"; echo"</form>"; echo"</td>"; echo"</tr>"; } //echo"</table>"; ?>
problem:
the html table isn't loading upon pressing button.the php page working when change form's action "delsubcategory.php" , button type="submit", issue lies html.
would appreciate insights matter
you forget wrap button click event handler $(function(){ });
<script type="text/javascript"> $(function(){ $("#viewsubcatsubmit").click(function(){ var cat=$('#viewsubcat').val(); $('#deletetable').load('delsubcategory.php?cat='+cat); }); }); </script>
Comments
Post a Comment