I'm trying to make a moderation form for a user submitted site. I grab the submissions to moderate from the MYSQL database using PHP, and make a dynamic page with HTML like this-
- <html><head>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/moderate.js"></script>
</head><body>
<div id="msg">Container</div>
<table border='1'><tr><td>Name</td><td>Email</td><td>Location</td><td>Chemistry</td><td>Approve/Deny</td></tr> <tr class="row">
<td>James</td>
<td>the@email.com</td>
<td>39.73915481567, -104.98470306396</td>
<td>11, 1, 1, 1, 1, 1</td>
<td id="474c23210a499fdabe3c84ea33cf021b2106b2ac"><div id="approval_form"><form name="approval" action="">
<input type="hidden" value="474c23210a499fdabe3c84ea33cf021b2106b2ac" name="hash" id="hash">
<input type="submit" value="Approve" name="submit" id="474c23210a499fdabe3c84ea33cf021b2106b2ac"></form><form name="delete" action="">
<input type="hidden" value="474c23210a499fdabe3c84ea33cf021b2106b2ac" name="hash" id="hash">
<input type="submit" value="Delete" name="submit" id="474c23210a499fdabe3c84ea33cf021b2106b2ac">
</form></div>
</tr>
<tr class="row">
<td>James</td>
<td>the@email.com</td>
<td>39.73915481567, -104.98470306396</td>
<td>11, 1, 1, 1, 1, 1</td>
<td id="50ca87f190e5de06794618df333d75b736e10175"><div id="approval_form"><form name="approval" action="">
<input type="hidden" value="50ca87f190e5de06794618df333d75b736e10175" name="hash" id="hash">
<input type="submit" value="Approve" name="submit" id="50ca87f190e5de06794618df333d75b736e10175"></form><form name="delete" action="">
<input type="hidden" value="50ca87f190e5de06794618df333d75b736e10175" name="hash" id="hash">
<input type="submit" value="Delete" name="submit" id="50ca87f190e5de06794618df333d75b736e10175">
</form></div>
</tr>
<tr class="row">
<td>James</td>
<td>the@email.com</td>
<td>39.73915481567, -104.98470306396</td>
<td>11, 1, 1, 1, 1, 1</td>
<td id="5b06c55569f420ef19f7ab27cdcc0d26e430d6c9"><div id="approval_form"><form name="approval" action="">
<input type="hidden" value="5b06c55569f420ef19f7ab27cdcc0d26e430d6c9" name="hash" id="hash">
<input type="submit" value="Approve" name="submit" id="5b06c55569f420ef19f7ab27cdcc0d26e430d6c9"></form><form name="delete" action="">
<input type="hidden" value="5b06c55569f420ef19f7ab27cdcc0d26e430d6c9" name="hash" id="hash">
<input type="submit" value="Delete" name="submit" id="5b06c55569f420ef19f7ab27cdcc0d26e430d6c9">
</form></div>
</tr>
<tr class="row">
<td>James</td>
<td>the@email.com</td>
<td>39.73915481567, -104.98470306396</td>
<td>11, 1, 1, 1, 1, 1</td>
<td id="a6443e90abd9572066fffcb5b1c231d2bc18b782"><div id="approval_form"><form name="approval" action="">
<input type="hidden" value="a6443e90abd9572066fffcb5b1c231d2bc18b782" name="hash" id="hash">
<input type="submit" value="Approve" name="submit" id="a6443e90abd9572066fffcb5b1c231d2bc18b782"></form><form name="delete" action="">
<input type="hidden" value="a6443e90abd9572066fffcb5b1c231d2bc18b782" name="hash" id="hash">
<input type="submit" value="Delete" name="submit" id="a6443e90abd9572066fffcb5b1c231d2bc18b782">
</form></div>
</tr>
</table></html>
These are id'd by a hash, which tells my PHP script to delete or approve the lines.
My jquery script works when I run it from the command line in Firebug (replacing an actual hash for 'this'), but when I load it, the things in the function(xml) part don't run. (I'll be adding a response from the server, but I'm just trying to get it working.
- $(document).ready(function() {
$("input").click(function(e){
// stop normal link click
e.preventDefault();
// send request
$.post("approve.php", { submit: $(this).val(), hash: $(this).attr('id')}, function(xml) {
// format and output result
$(this).parents(".row").html("<td colspan=5>It worked</td>");
$("#msg").html("<p>One Did</p>");
});
});
$("input").css("border", "1px solid black");
});
Any idea how I can make this work? I'm open to ideas on how to better pass the hash & approve or delete to the server as well.
Thanks!