Jump to content

Onclick not working?


Tenaciousmug

Recommended Posts

Ok here is my form:

$sql = "SELECT storage.quantity, items.name, items.image, items.description, items.itemid
FROM storage
JOIN items USING(itemid)
WHERE userid='".$_SESSION['userid']."'
ORDER BY items.name
LIMIT $offset, $rowsperpage";
$result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn));
$imagecount = 0;
$tableOutput = "";
while ($row = mysqli_fetch_assoc($result)) //while there are still results
{
	$imagecount++;
	$quantity = $row['quantity'];
	$name = $row['name'];
	$image = $row['image'];
	$description = $row['description'];
	$itemid = $row['itemid'];

	//Create TD
	$tableOutput .= "<tr>\n";
	$tableOutput .= "<td width=\"50\" style=\"text-align:center;\">\n";
	$tableOutput .= "<img src=\"http://www.elvonica.com/".$image."\"><br>";
	$tableOutput .= $name."</td>\n";
	$tableOutput .= "<td width=\"400\" style=\"text-align:center;\">".$description."</td>\n";
	$tableOutput .= "<td width=\"50\" style=\"text-align:center;\">".$quantity."</td>\n";
	$tableOutput .= "<td width=\"100\" style=\"text-align:center;\">\n";
	$tableOutput .= "<button type=\"button\" onclick=\"removeOne(".$itemid.")\">Remove 1</button><br />\n";
	$tableOutput .= "<button type=\"button\" onclick=\"removeAll(".$itemid.")\">Remove All</button>\n";
	$tableOutput .= "</td>\n";
	$tableOutput .= "</tr>\n";
}
	echo "<form action=\"storageprocess.php\" method=\"get\">\n";
	echo "<table cellspacing=\"0\" class=\"news\" align=\"center\">\n";
	echo "<tr>\n";
	echo "<td width=\"50\" style=\"text-align:center;background-color:#EEEEEE;\"><b>Item</b></td>\n";
	echo "<td width=\"400\" style=\"text-align:center;background-color:#EEEEEE;\"><b>Description</b></td>\n";
	echo "<td width=\"50\" style=\"text-align:center;background-color:#EEEEEE;\"><b>Quantity</b></td>\n";
	echo "<td width=\"100\" style=\"text-align:center;background-color:#EEEEEE;\"><b>Remove</b></td>\n";
	echo "</tr>\n";
	echo $tableOutput;
	echo "</table><br />\n";
	echo "</form>\n";

Just ignore the PHP part of it. This is going through a while loop as you can see, but the function "removeOne()" and "removeAll()" has the itemid in the parantheses so the javascript can catch that value.

But the problem is, that it's not even catching the function.

One of the functions (removeOne) looks like this:

 

<script>
$(document).ready(function() {
function removeOne(n)
{
	alert("hi");

	$.ajax(
	{
		type: "GET",
		url: "storageprocess.php?itemid="+ n,
		data: "itemid="+ n,
		success: function()
		{
			alert("Item has been moved to inventory.");
		}
	});
}
});
</script>

Just ignore the AJAX part. I put the alert("hi"); in the beginning to see if it's even catching the onclick and it's not. So I don't understand why the onclick isn't preparing the function..

Can anyone help me here?

Link to comment
Share on other sites

first thing, you are trying to call a javascript event using php, I would not recommended this since php is executed on the server and js is executed on the client. The intermixing of the two usually results in unexpected results. Why not add to your jquery code a bit and add an .click event to trigger your functions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.