Forum Moderators: open
On the page I want two radio buttons: approve and delete. Then depending on which is 'checked' the form is either submitted to 'comments.php?app=1' OR 'comments.php?del=1'.
Note: If I visit either of those two given addresses, PHP does it's thing. That part of my code works great (uses POST data as well, to specify which comment to approve or delete, just to clarify).
My javascript isn't changing the form action though! I've looked over my code over and over and I an clueless as to why it's not doing it. Here's some source:
<script type="text/javascript" language="JavaScript">
function deleteapprove() {
if(document.forms[0].radio[0].checked == true) {
document.forms[0].action = 'comments.php?app=1';
return false;
}
if(document.forms[0].radio[1].checked == true) {
document.forms[0].action = 'comments.php?del=1';
return false;
}
}
</script>
<?php
$query1 = mysql_query("SELECT * FROM comments WHERE `is_approved`='0'");
while ($result = mysql_fetch_array($query1)) {
for ($i = 0; $i < mysql_num_rows($query1);) {
echo "<div style=\"border:2px solid black;padding:2px 2px 2px 0px;\">";
echo "{$result['page']} - Article {$result['art_id']}";
echo "<form name=\"appordel\" method=\"POST\" onSubmit=\"return deleteapprove()\">";
echo "<b>$result[name] ¦ </b></a>";
echo "<small><i>$result[date]</i> ¦ ";
echo "$result[comments]</small> ¦ <br /><hr width='25%' align='left'><br />";
echo "<input type=\"hidden\" name=\"del\" value=\"$result[com_id]\">";
echo "<input type=\"hidden\" name=\"app\" value=\"$result[com_id]\">";
echo "Approve <input type=\"radio\" name=\"option\">";
echo "Delete <input type=\"radio\" name=\"option\">";
echo "<input type=\"submit\" value=\"<-- Do it!\">";
echo "</form>";
/*echo "<img src=\"images/articles/$result[photo].jpg\" style=\"float:right;\">";*/
echo "<br /><br />";
echo "</div>";
break;
}}
I'm really trying to get this working...any ideas?
Thanks in advance!
depending on which is 'checked' the form is either submitted to 'comments.php?app=1' OR 'comments.php?del=1'
You shouldn't even have to do this, you should be able to just submit to comments.php and parse out the value of the selected radio button. Change the name of the radio button to something like
<input type="radio" name="comment_action" value="approve" checked> Approve
<input type="radio" name="comment_action" value="delete"> Delete
Then in your PHP script, you just act on whatever the value of comment_action is.