Jes Se Jes Se - 3 months ago 9
Javascript Question

How to alert id when different row is clicked?

I have two results in my select db which are text_1 and text_2 they have different ids, but when I click text_2 it alerts the id of text_1

my php echo

echo'<p><input id="textid" type="hidden" value="'.$msg->id.'">'.$msg->text.'</p>';


this is my js code

var getid= document.getElementById('textid').value;
$("p").click(function(){
alert(getid);
});

Answer

PHP

echo'<p><input id="textid_1" type="hidden" value="'.$msg->id.'">'.$msg->text.'</p>';
echo'<p><input id="textid_2" type="hidden" value="'.$msg->id.'">'.$msg->text.'</p>';

JS

$("p").click(function(){
    alert($(this).find("input").val());
});