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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:02:54+00:00 2026-06-10T11:02:54+00:00

I been trying to find a solution for this for a long time and

  • 0

I been trying to find a solution for this for a long time and would really appreciate any help.

I have a table which is generated through a php sql query beside each row is two buttons Buy & Sell when the user clicks on either of the buttons it would populate an order form which is in a dialog box

I have a function which acts on the click event in jQuery but its reading the first fields of the first row in the table.

here is my function

$('.buy').click(function(){
if($('#buying').dialog('isOpen')) alert('Buy Box Already open');
else { 
   $(".buycommodity").val($(".commodity_name").val()+"
                 "+$(".commodity_code").val());
      $("#buyprice").val($(".commodity_price").val());
      $("#buyqty").val($(".commodity_volume").val());


      $('#buying').dialog('open'); 
    }}
    );

The question, how can I get the correct fields read and populated in the form? How can I get jQuery to know which button, on which row is clicked? All the type button have the same class i.e buy or sell

here is some HTML source of the table

<div id="exchange">
<form>
<table border="1" cellspacing="5" cellpadding="5">
<tr>
    <th>Commodity</th>
    <th>Code</th>
    <th>Current Price</th>
    <th>Past Price</th>
    <th>Change</th>
    <th>Volume</th>
        </tr>
        <tr valign='top'>
<td align=left>
   <input type="text" name="commodityname" value=Basmati readonly="readonly" id="commodityname" size=10>
</td>
<td align=left>
   <input type="text" name="commoditycode" value=1121 readonly="readonly" id="commoditycode" size=6>
</td>
<td align=absmiddle>
   <input type="text" name="currentprice" value=100 readonly="readonly" id="currentprice" size=4>
</td>
<td align=absmiddle>
   <input align=absmiddle type="text" name="pastprice" value=80 readonly="readonly" id="pasrprice" size=4>
</td>
<td align="absmiddle"><font size="3" color="blue"><em>&#x25B2;</em></font></td>
<td align=left><input type="text" name="commodityvolume" value=88000 readonly="readonly" id="commodityvolume" size=7>
</td>
   <input type=hidden id=commodity_id name=commodity_id value=1>
   <input type=hidden class=commodity_name name=commodity_name value=Basmati>
   <input type=hidden class=commodity_code name=commodity_code value=1121>
   <input type=hidden class=commodity_volume name=commodity_volume value=88000>
   <input type=hidden class=commodity_price name=commodity_price value=100>
<td>
   <input class=buy type=button name=orderbutton value=Buy>
</td>
<td>
   <input class=sell type=button name=orderbutton value=Sell>
</td>
</tr>
</form>
<tr valign='top'>
   <td align=left>
      <input type="text" name="commodityname" value=Basmati readonly="readonly" id="commodityname" size=10>
   </td>
   <td align=left>
      <input type="text" name="commoditycode" value=386 readonly="readonly" id="commoditycode" size=6>
  </td>
  <td align=absmiddle>
      <input type="text" name="currentprice" value=90 readonly="readonly" id="currentprice" size=4>
  </td>
  <td align=absmiddle><input align=absmiddle type="text" name="pastprice" value=100 readonly="readonly" id="pasrprice" size=4>
  </td>
  <td align="absmiddle"><font size="3" color="red"><em>&#x25BC;</em></font></td>
  <td align=left><input type="text" name="commodityvolume" value=44000 readonly="readonly" id="commodityvolume" size=7>
  </td><input type=hidden id=commodity_id name=commodity_id value=2>
   <input type=hidden class=commodity_name name=commodity_name value=Basmati>
   <input type=hidden class=commodity_code name=commodity_code value=386>
   <input type=hidden class=commodity_volume name=commodity_volume value=44000>
   <input type=hidden class=commodity_price name=commodity_price value=90><td>
   <input class=buy type=button name=orderbutton value=Buy></td>
                         <td><input class=sell type=button name=orderbutton value=Sell></td></tr
   </form>
 <tr valign='top'>
   <td align=left>
     <input type="text" name="commodityname" value=Basmati readonly="readonly" id="commodityname" size=10></td>
     <td align=left><input type="text" name="commoditycode" value=385 readonly="readonly" id="commoditycode" size=6></td>
    <td align=absmiddle><input type="text" name="currentprice" value=75 readonly="readonly" id="currentprice" size=4>
    </td>
    <td align=absmiddle><input align=absmiddle type="text" name="pastprice" value=88 readonly="readonly" id="pasrprice" size=4></td>
    <td align="absmiddle"><font size="3" color="red"><em>&#x25BC;</em></font></td>
    <td align=left>
      <input type="text" name="commodityvolume" value=24000 readonly="readonly" id="commodityvolume" size=7></td>
      <input type=hidden id=commodity_id name=commodity_id value=3>
      <input type=hidden class=commodity_name name=commodity_name value=Basmati>
      <input type=hidden class=commodity_code name=commodity_code value=385>
      <input type=hidden class=commodity_volume name=commodity_volume value=24000>
      <input type=hidden class=commodity_price name=commodity_price value=75><td>
      <input class=buy type=button name=orderbutton value=Buy></td>
                         <td><input class=sell type=button name=orderbutton value=Sell></td></tr>
      </form>
      <tr valign='top'><td align=left>
      <input type="text" name="commodityname" value=Ierro readonly="readonly" id="commodityname" size=10></td><td align=left>
      <input type="text" name="commoditycode" value=6 readonly="readonly" id="commoditycode" size=6></td><td align=absmiddle>
      <input type="text" name="currentprice" value=33 readonly="readonly" id="currentprice" size=4></td><td align=absmiddle>
      <input align=absmiddle type="text" name="pastprice" value=39 readonly="readonly" id="pasrprice" size=4></td><td align="absmiddle"><font size="3" color="red"><em>&#x25BC;</em></font>
    </td><td align=left>
      <input type="text" name="commodityvolume" value=124000 readonly="readonly" id="commodityvolume" size=7></td>
      <input type=hidden id=commodity_id name=commodity_id value=4>
      <input type=hidden class=commodity_name name=commodity_name value=Ierro>
      <input type=hidden class=commodity_code name=commodity_code value=6>
      <input type=hidden class=commodity_volume name=commodity_volume value=124000>
      <input type=hidden class=commodity_price name=commodity_price value=33><td>
      <input class=buy type=button name=orderbutton value=Buy></td>
      <td><input class=sell type=button name=orderbutton value=Sell></td></tr></form>
<tr valign='top'><td align=left>
      <input type="text" name="commodityname" value=Ierro readonly="readonly" id="commodityname" size=10>
  </td>
     <td align=left>
      <input type="text" name="commoditycode" value=9 readonly="readonly" id="commoditycode" size=6></td><td align=absmiddle>
      <input type="text" name="currentprice" value=79 readonly="readonly" id="currentprice" size=4></td><td align=absmiddle>
      <input align=absmiddle type="text" name="pastprice" value=60 readonly="readonly" id="pasrprice" size=4></td><td align="absmiddle"><font size="3" color="blue"><em>&#x25B2;</em></font></td><td align=left>
      <input type="text" name="commodityvolume" value=24000 readonly="readonly" id="commodityvolume" size=7></td>
      <input type=hidden id=commodity_id name=commodity_id value=5>
      <input type=hidden class=commodity_name name=commodity_name value=Ierro>
      <input type=hidden class=commodity_code name=commodity_code value=9>
      <input type=hidden class=commodity_volume name=commodity_volume value=24000>
      <input type=hidden class=commodity_price name=commodity_price value=79><td>
      <input class=buy type=button name=orderbutton value=Buy></td>
      <td><input class=sell type=button name=orderbutton value=Sell></td></tr></form></table
      </div>
  • 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-10T11:02:56+00:00Added an answer on June 10, 2026 at 11:02 am

    I hope this helps you out:

    $('.buy').click(function() {
     var trRef=$(this).parent().parent(); //double parent() to get reference of TR, that holds the button in action
     var commodity_name = $(trRef).find('.commodity_name').val();
     var commodity_code = $(trRef).find('.commodity_code').val();
     var commodity_price = $(trRef).find('.commodity_price').val();
     var commodity_volume = $(trRef).find('.commodity_volume').val();
    
     $(".buycommodity").val(commodity_name+" "+commodity_code);
      $("#buyprice").val(commodity_price);
      $("#buyqty").val(commodity_volume);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to find a solution to this one but could not
I have been trying to find a solution for this for a while but
I have been trying to find a solution to this everywhere but am stumped.
I have been trying to find decent Image Acquisition + Image Processing solution at
Been trying to find this online for a while now. I have a SDL_Surface
I have a problem that I have been trying to find a solution for
Been trying to find a solution for this for a while with not much
Ok, I've been trying to find a solution for this for about half a
I am really at a loss here, and have been trying to find a
I've been trying to find a solution to this, but perhaps I'm not understanding

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.