0

hi guys i need another idea how to make this happend i got a loop on my script that shows id for each member and i want to pass a variable for each member this is an example

<?php    
     $loopvalue = $playerCount; 
     $i=1; 
     while ($i <= $loopvalue) { 
         $uid = $data['players'][$i-1]['avatar']['userId'];
  ?>

 <input class="user_id_imput" type="hidden" name="id" value="<?php echo $uid;?>" />
 <a href="#" class="Send_user_id"><?php echo $userName;?></a></span>

<?php  
        $i++;
    }; 
?>

and using jquery to show the variable with this

     $(".Send_user_id").click(function() {
        var uid  = $(".user_id_imput").val();
        console.log('id: ' + uid ); 
      });   

normaly i do this when not using a loop bu in this case i cant think of a diferent way to do it

using this will give me the id of the first result for all the results any idea how i can pass the id var for each result?

thanks for you help

2 Answers 2

1

Assuming that your <a> tag and <input> tags are back to back; you can use following approach:

$(".Send_user_id").click(function() {
    var uid  = $(this).prev(".user_id_imput").val();
    console.log('id: ' + uid ); 
});  

$.prev() Get the immediately preceding sibling

Sign up to request clarification or add additional context in comments.

Comments

0

thanks for the help you gave me an idea instead of using the input using data-id to pass the variable so the result code will be

php

<a data-id="<?php echo $uid;?>" href="#" class="Send_user_id"><?php echo $userName;?></a></span>

jquery

     $(".Send_user_id").click(function() {
        var uid  = $(this).attr('data-id');
        console.log('id: ' + uid ); 
  }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.