Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:24:52+00:00 2026-05-28T18:24:52+00:00

i am trying to bind an id to a tag. not sure if i

  • 0

i am trying to bind an id to a tag. not sure if i should do a bind
but i hope my example would help to explain what i am trying to do.
i have a php for loop that gives me a series of numbers

<?php

         for($value = 1; $value <=5; $value++){
         print '<br><form><input id="hidden" type="hidden" value="'.$value.'" /><a id="link">click here</a><form>';
         }
         ?>

in my html i have a field within a form when the while loop is executed html looks like this

<input id="hidden" type="hidden" value="1" /><a id="link">click here</a>
<input id="hidden" type="hidden" value="2" /><a id="link">click here</a>
<input id="hidden" type="hidden" value="3" /><a id="link">click here</a>

my aim is this. if i click on the first ‘click here’ i want to output the hidden value of 1
if i click on the second ‘click here’ i want to output hidden value of 2 and etc.. my problem
is that when i click on either link, i only get back the value of the first ‘click here’ which is 1

this is my jquery code.

<script>
$(document).ready(function(){ 
    $("a#link").click(function(){
    var s = $('.hidden').val();
 alert(s); 
 }); 
}); 
</script>

thanks for your help in advance…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:24:53+00:00Added an answer on May 28, 2026 at 6:24 pm
    $('.hidden').val()
    

    will always just give you the first hidden val in the DOM. You need

    $(this).prev("#hidden").val()
    

    See this fiddle: http://jsfiddle.net/RJJEr/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to bind a list of data to a data grid, but can't
Hi I'm trying to bind data to a kendochart, but no bars are appearing
I'm trying to bind parameters in what I think is the correct way, but
I am trying to stop some events but stopPropagation does not work with live
Well, not literally, of course, but: I'm new to Flex and I'm trying to
Currently trying to bind the mouseenter or hover events for a Input tag, my
I am trying to specialize some utility code on const member functions, but have
I'm stuck trying to bind a click redirect to the body tag on a
I am trying to bind the anchor tag link to my source. Actual need
I'm trying to bind a function to the anchor onclick attribute. I'm not using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.