I have a very similar problem, but i cant seem to figure it out, it could be that i have been trying to do this for the past 14 hours... my problem is: I cant get this to return the corresponding customer id, it just always returns the first one. here is the code
<div id="saveAdButtons">
<?php
if ($limit == 5){
for ($i=0;$i<$count;++$i){
$results33 = mysql_query("SELECT * FROM saved_ads WHERE customer_id='{$contact_id}'") or die(mysql_error());
$data2222 = mysql_fetch_array($results33);
$idCheck = $data2222['customer_id'];
if($ids[$i]!=$idCheck){?>
<button name="contact_ids[]" class="contact_ids" id="contact_ids0" title="Save Ad: <?php echo $ids[$i]?>" value="Save Ad" ></button>
<input name="parse" id="SaveBtnID" type="hidden" value="<?php echo $ids[$i] ?>" /><br /><br /><br /><br /><br />
<?php
} } }?>
Here is JQUERY code
$(document).ready(function(){
$( "#contact_ids0" ).live('click',function(event){
what should I put here??.. i have tried
var tr = $(this).closest('I DONT KNOW WHAT TO PUT HERE'); //
tr.find('#I DONT KNOW WHAT TO PUT HERE').empty(); //
var vidid = tr.find('#SaveBtnID').val();
but it returns the first id only, no matter which button i click :(
var datastr2="ids="+CusID;
alert(CusID);
return true;
});
});
thank you in advance! :)
I'm not sure of what you want but here I would like to explain this to you
you are using
$("#contact_ids0").live
this refers to the id specifically so it is expected to return only 1 result
while if you will use this
$(".contact_ids").live
you can select all the buttons having the same class because dot "." refers to the class therefore this will do the trick
$(".contact_ids").live('click',function(){
alert($(this).attr('id'));
});
and if you wanted to loop to all the classes you can do this
$(".contact_ids").each(function(){
alert($(this).attr('id'));
});
Well, first of all, you shouldn't be using the same ID for all of those inputs - an ID is for ONE element, and that element only. jQuery is noticing that you are searching for an ID, and based on what I told you, is returning one element, and getting it's value.
Secondly, .val() is built where it will only return the value of the first element in an object.
Finally, you should be using a CLASSES for this. A class can be used on more than one element. This way, all of your hidden inputs will be stored in one object, and you can sort through them. You need to loop through the inputs and get their values, the code below should get you started:
$(".contact_ids").each(function(i, el){
alert($(el).val());
});