JQuery/PHP - passing a value to JQuery when image is clicked?

polarbear

New member
there is a much simpiler way

<script>
$(document).ready(function()
{
$("img.ImgButtonClassName").click(function()
{
var buttonid = $(this).attr("buttonid");
//do other stuff here
});
});
</script>
and in each of the img tags put buttonid="someidnumber" and a custom named css class
so
<img src="trash.jpg" class="ImgButtonClassName" buttonid="someidnumber">

No need for the anchor tags or the onclick events as jquery takes care of setting up event handlers.
----------------------
Yahoo answers is cutting off part ofthe script
the .click thing is supposed to be .click(function()
 
there is a much simpiler way

<script>
$(document).ready(function()
{
$("img.ImgButtonClassName").click(function()
{
var buttonid = $(this).attr("buttonid");
//do other stuff here
});
});
</script>
and in each of the img tags put buttonid="someidnumber" and a custom named css class
so
<img src="trash.jpg" class="ImgButtonClassName" buttonid="someidnumber">

No need for the anchor tags or the onclick events as jquery takes care of setting up event handlers.
----------------------
Yahoo answers is cutting off part ofthe script
the .click thing is supposed to be .click(function()
 
I am trying to get into JQuery but can't figure out how to pass values from the body of my page to the JQuery script. The situation I have is this;

In the body, I have a list of buttons dynamically generated from a database using PHP. The buttons are arranged using a JQuery sortable list, each of which has a small "trash" icon. I want to assign the id of each button to the trash icon so that when it is clicked, the id of the button is passed to the JQuery script and an Ajax
call is fired off with the button id to a PHP script that will delete the button.

I am not sure of 2 things;

1. Where to place the button id in the anchor tag - I am not sure if I should use <a href="javascript:butId('<?= $butid ?>')" class="blah">Trash icon</a> or something else.

2. How would the JQuery script pick the button Id value up?
 
there is a much simpiler way

<script>
$(document).ready(function()
{
$("img.ImgButtonClassName").click(function()
{
var buttonid = $(this).attr("buttonid");
//do other stuff here
});
});
</script>
and in each of the img tags put buttonid="someidnumber" and a custom named css class
so
<img src="trash.jpg" class="ImgButtonClassName" buttonid="someidnumber">

No need for the anchor tags or the onclick events as jquery takes care of setting up event handlers.
----------------------
Yahoo answers is cutting off part ofthe script
the .click thing is supposed to be .click(function()
 
there is a much simpiler way

<script>
$(document).ready(function()
{
$("img.ImgButtonClassName").click(function()
{
var buttonid = $(this).attr("buttonid");
//do other stuff here
});
});
</script>
and in each of the img tags put buttonid="someidnumber" and a custom named css class
so
<img src="trash.jpg" class="ImgButtonClassName" buttonid="someidnumber">

No need for the anchor tags or the onclick events as jquery takes care of setting up event handlers.
----------------------
Yahoo answers is cutting off part ofthe script
the .click thing is supposed to be .click(function()
 
Back
Top