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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:40:53+00:00 2026-06-11T21:40:53+00:00

I have a table as below. I have to populate the Amount field using

  • 0

I have a table as below. I have to populate the Amount field using the Buy Quantity and Market Price field. Amount = Buy Quantity*Market Price. I am doing something as –

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Buy Stocks</title>

<script>
(function(){

var table = document.getElementById("mytable");
var tbody = table.getElementsByTagName("tbody")[0];
var rows = tbody.getElementsByTagName("tr");
function populateRow(index, addBlurEvent){
    var row = rows[index];
var cells = row.getElementsByTagName("td")
    var textboxes = row.getElementsByTagName("input");
var amountTextbox = textboxes[0];
    var totalTextbox = textboxes[1];
    var costCell = cells[2];
    var amount = amountTextbox.value.length>0 ? parseFloat(amountTextbox.value) : 0;
    var cost = parseFloat(costCell.innerHTML);
var total = amount * cost;
    totalTextbox.value = total;
if (addBlurEvent) {
        amountTextbox.onblur = function(){ populateRow(index,false); };
    }
}
for(i=0;i<rows.length;i++){
    populateRow(i,true);    
}
})();


</script>
</head>
<body>
<center>

<h5>Buy Stocks Here</h5>
    <form >
   <table border="1" cellpadding="5" id="mytable">
    <thead>
      <tr>
        <th>Stock Name</th>
        <th>Buy Quantity</th>
        <th>Market Price</th>
        <th>Amount</th>
      </tr>
    </thead>
    <tbody>
<tr>
        <td>Stock Name</td>
        <td><input type="text" name="quantity" ></td>
        <td>122</td>
        <td><input type="text" name="amount"></td>
      </tr>

      <tr>
        <td>Stock Name</td>
        <td><input type="text" name="quantity" ></td>
        <td>111</td>
        <td><input type="text" name="amount"></td>
      </tr>

    </tbody>
  </table>
 </form>
</center>

The above html’s javascript function is supposed to work perfectly, I am not able to handle the ‘onblur’ event. How and where should I do that? Please suggest an answer which does not modify the script. Thanks.

Image for reference :

enter image description here

  • 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-11T21:40:54+00:00Added an answer on June 11, 2026 at 9:40 pm

    See this: http://jsfiddle.net/picklespy/cxUz9/

    If you want to use your code only and not the jquery one that i gave above, please use this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Buy Stocks</title>
    </head>
    <body>
    <center>
    
    <h5>Buy Stocks Here</h5>
        <form >
       <table border="1" cellpadding="5" id="mytable">
        <thead>
          <tr>
            <th>Stock Name</th>
            <th>Buy Quantity</th>
            <th>Market Price</th>
            <th>Amount</th>
          </tr>
        </thead>
        <tbody>
    <tr>
            <td>Stock Name</td>
            <td><input type="text" name="quantity" ></td>
            <td>122</td>
            <td><input type="text" name="amount"></td>
          </tr>
    
          <tr>
            <td>Stock Name</td>
            <td><input type="text" name="quantity" ></td>
            <td>111</td>
            <td><input type="text" name="amount"></td>
          </tr>
    
        </tbody>
      </table>
     </form>
    </center>
    <script type="text/javascript">
    (function(){
    
    var table = document.getElementById("mytable");
    var tbody = table.getElementsByTagName("tbody")[0];
    var rows = tbody.getElementsByTagName("tr");
    function populateRow(index, addBlurEvent){
        var row = rows[index];
    var cells = row.getElementsByTagName("td")
        var textboxes = row.getElementsByTagName("input");
    var amountTextbox = textboxes[0];
        var totalTextbox = textboxes[1];
        var costCell = cells[2];
        var amount = amountTextbox.value.length>0 ? parseFloat(amountTextbox.value) : 0;
        var cost = parseFloat(costCell.innerHTML);
    var total = amount * cost;
        totalTextbox.value = total;
    if (addBlurEvent) {
            amountTextbox.onblur = function(){ populateRow(index,false); };
        }
    }
    for(i=0;i<rows.length;i++){
        populateRow(i,true);    
    }
    })();
    </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider I have a table, like below, that I am trying to populate with
I am using Jquery to dynamically populate the table element. My table will have
Populate php array into HTML table I have data in a php array (say,
I have a GridView using LinqDataSource to populate data from table Tickets . The
i have the table below <tr id=group_1>...</tr> <tr id=el>...</tr> <tr id=el>...<tr> <tr id=group_2></tr> <tr
I have a table like below: Table A ---------- ID Field1 Field2 Field3 1
I have a table as below ID Date 1 Null 1 Null 1 Null
I have a table as below Name Priority Date ------------------------- A 2 d1 B
I have a table like below: EmployeeId EmployeeName RequestId RequestName EmployeeId RequestId I need
I have a table as below dbo.UserLogs ------------------------------------- Id | UserId |Date | Name|

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.