I want to if any one click on image than only clicked image sl number pass to php page. but i don’t get any imge sl number. I am trying to find out the problem. but i can’t please, any one help me. thanks. here is my code
<?php
$query="select * from image_content order by sl";
$result=mysql_query($query) or die (mysql_error());
$num=mysql_num_rows($result);
for ($i=0; $i<$num; $i++)
{
$sl=mysql_result($result, $i, "sl");
$title=mysql_result($result, $i, "title");
$image_name=mysql_result($result, $i, "image_name");
echo"
<div id='image_style'>
<div id='upload_image'>
<a class='picture_description' href='#' title='$title'>
<img src='../download/$image_name' />
<div align='center'>Title: $title</div>
</a>
</div>
<input type='hidden' class='picture_sl' name='picture_sl' value='$sl'/>
</div>";
}
?>
jquery code:
<script type="text/javascript">
$(document).ready(function() {
$(".picture_description").click(function() {
var action = $("#form1").attr('action');
var form_data = {
picture_sl: $(".picture_sl").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response)
{
$("#div_1").html(response);
}
});
return false;
});
});
</script>
loaded php:
<?php
echo $picture_sl=$_POST['picture_sl'];
?>
In your click handler you are selecting any input element with the class “picture_sl”, not the one that was clicked.
You could use a data attribute on your anchor tag like this
and then retrieve it with the jQuery data() method: