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 9036567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:02:08+00:00 2026-06-16T09:02:08+00:00

I looped my html, and wish to get specific field value when the user

  • 0

I looped my html, and wish to get specific field value when the user clicked the button.
I am having headahce to retrieve the correct value please help me out.

<div id="tabs1">
<table>
{foreach from=$this->products item=p}               
<tr>
<td><div class="tabs-product">
<div>
<input type='hidden' id='item' name='item' value='{$p.name}'/>
<input type='hidden' id='price' name='price' value='{$p.price}'/>
<button class="shareButton" onclick='post(); return false;'>Share</button>
</div></td></tr>
{/foreach}
</table></div>

<script>
 function post() {
    var item =  $(this).parent("tabs-product").attr("input");//this cause undefined
    var price = $('#price').val(); //this method only get first value
    alert(item + price);
}
</script>
  • 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-06-16T09:02:10+00:00Added an answer on June 16, 2026 at 9:02 am
    var $product = $(this).closest('.tabs-product');
    var item = $product.find('input[name="item"]').val();
    var price = $product.find('input[name="price"]').val();
    
    • input is an element, not an attribute.
    • You can’t use absolute IDs like in your $('#price'), since you have several elements with identical IDs (printed by a loop) – it is both illegal by spec (but permitted by lax browsers), and useless
    • Using input[name="..."] selector, you can pinpoint which input element within the product you actually need.
    • In this case, parent and closest work equally well, but I like closest better for the flexibility in these kinds of cases, if you change your mind about the structure and decide to insert an extra element, for layout or whatever other reason. EDIT: As noted by TJ in comments, I missed the <div>, which just drives this point home.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following HTML which has been looped around in smarty template language:
I am implementing the looped slider plugin (see: http://nathansearles.com/loopedslider/example-4.html ) on a website, and
I have looked at the LuaJIT tutorial at: http://luajit.org/ext_ffi_tutorial.html I am trying to get
I've my HTML codes as <li><button id=1 class=vote btn type=button /></li> <li><button id=2 class=voteUp
I would like to output some specific HTML on the third iteration of a
If my html looked like this: <td class=controlCell> <input class=inputText id=SearchBag.CompanyName name=SearchBag.CompanyName type=text value=
I've looked for tutorials on using HTML Agility Pack as it seems to do
I've looked at free javascript html editors, and I haven't found any that I
I've looked at http://code.google.com/appengine/docs/java/urlfetch/overview.html but the code does not show a pooling example, i
I have looked at the documentation here: http://docs.python.org/dev/library/xml.etree.elementtree.html#xml.etree.ElementTree.SubElement The parent and tag argument seems

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.