Forum Moderators: open

Message Too Old, No Replies

Changing form action, strange problem

changing form action with javascript

         

xKillswitchx

9:49 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



Hello all,
I have a webapp I am developing in PHP and am almsot at a complete loss in dealing with Javascript (I don't know it, but I for the most part, can understand it and enough to edit slightly).

I have a list of content items that is grabbed from a mysql database through a loop in PHP. For each content item, I have a checkbox. want I found I really needed, was the option to change the forms action URL with Javascript, so I dug up a script to do so...

function OndeleteContent()
{
document.contentForm.action = "?task=content&action=delete_content"
document.contentForm.target = "_self"; // Open in a new window
document.contentForm.submit(); // Submit the page
return true;
}

Thats the Javascript I use for deleting items. Should work in conjunction with this ...

<form name="contentForm" method="post" action="">

<input type="image" src="templates/images/delete_content.gif" alt="Delete Content" class="contentOption" name="OndeleteContent" onclick="return OndeleteContent();">

The Javascript and image submit sends me to the appropriate page, but doesnt appear to be sending any of the data with it. I checked to see if the form submittion was set through PHP, else return a message "Not set" and I costantly retrive Not Set message. Not sure if this is a PHP error or something with the Javascript, but here is also a small bit of the PHP...

if (isset($_POST['OndeleteContent']))
{
foreach($_POST['checkbox'] as $id)
{
$sql = "DELETE FROM content WHERE id = '$id'";
$result = mysql_query($sql) or die("Error in Query");
}
}
else {
echo "Not set";

}

Can anyone help diagnose this issue? If it helps, I have other options to edit items, publish, and unpublish items, which are all controlled by similar methods (Javascript functions). I would link to live example, but I am testing locally through XAMPP.

vincevincevince

5:29 am on Aug 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are submitting through the .submit() method, not through that image click. Remove the call to submit() on the onClick and it should work fine.