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

  • Home
  • SEARCH
  • 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 7829543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:49:06+00:00 2026-06-02T10:49:06+00:00

With php I generate a form based on a multidimensional array. The form contains

  • 0

With php I generate a form based on a multidimensional array. The form contains a number of input type=”text” fieldpairs that are named “items[level1][level2][price]” and “items[level1][level2][amount]”. I display these in a table.

Now, I want to add two things using jquery:

  1. an extra column that displays the total price for this item (=items[level1][level2][price].value * items[level1][level2][amount].value)
  2. At the bottom row: the total price for all items.

These values should update on every change-event of one of the mentioned textinputs.

I’ve been hitting a wall the last few hours, I hope someone here could give me some pointers.

Here’s a snippet of the generated html:

<form name="formname">
<table name="tablename">
    <tr>
        <td><input type="text" class="classname" name="items[1][2][amount]" /></td>
        <td><input type="text" class="classname" name="items[1][2][price]" /></td>
        <td>Here I want to display amount*price</td>
    </tr>
    <tr>
        <td><input type="text" class="classname" name="items[1][8][amount]" /></td>
        <td><input type="text" class="classname" name="items[1][8][price]" /></td>
        <td>Here I want to display amount*price</td>
    </tr>
    <tr>
        <td><input type="text" class="classname" name="items[3][4][amount]" /></td>
        <td><input type="text" class="classname" name="items[3][4][price]" /></td>
        <td>Here I want to display amount*price</td>
    </tr>
    ...more rows like above...
    <tr>Some more formelements that have nothing to do with the problem</tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Here I want to display the sum of all amount*price</td>
    </tr>
</table>
</form>
  • 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-02T10:49:13+00:00Added an answer on June 2, 2026 at 10:49 am

    There are a few ways you could do it. The basic idea is when the .classname input changes, look for the parent row and then use that to look for the inputs in that row to multiply together and the td to put the value it. You can look for them using a “name contains” [attr*=string] selector:

    $('.classname').on('change', function() {
        var row = $(this).closest('tr');
        var total = row.find('[name*=amount]').val() * row.find('[name*=price]').val();
    
        row.find('td:last').text(total);
    });
    

    Demo: http://jsfiddle.net/jtbowden/DJtTs/

    Or if they are always the 1st/2nd column, use .eq() or :eq():

    $('.classname').on('change', function() {
        var row = $(this).closest('tr');
        var total = row.find('input:eq(0)').val() * row.find('input:eq(1)').val();
    
        row.find('td:last').text(total);
    });
    

    Demo: http://jsfiddle.net/jtbowden/DJtTs/1/

    EDIT MARCO:

    $(".classname").live('change', function(e) {
        //replaced on with live so the function will stick.
        var row = $(this).closest('tr');
        var total = row.find('[name*=amount]').val() * row.find('[name*=price]').val();
        row.find('[id="totalitemprice"]').text("\u20ac "+total.toFixed(2));
        //added eurosign and rounded to 2 decimals
    
        //Start computing total value
        var totaltotal = parseFloat(0);
        $.each($('[id="totalitemprice"]'), function(key, value) {
            //Loop across all totalitemprices
            totaltotal += parseFloat(value.firstChild.data.replace(/\u20ac /g,''));
            //Find out what's in the cell, strip the eurosign, parse it to Float and add it to the total
        });
    
        $("#totalprice").text("\u20ac "+totaltotal.toFixed(2));
        //Finally, write the total price to the approprioate cell.
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the input button is in index.php <form method=post action=1.php,2.php,3.php> <input type=text name=search id=search class='search'/>
I'm using php to generate an html page that displays blog/thread items, and I
I am creating a form designer. It will generate PHP code which will produce
Basically I hate a satellite website that is including form.php from an entirely different
I have a CGI based form that I am working with and I would
I have a form that allows the user to either upload a text file
Can one use the php DOM class - http://php.net/manual/en/book.dom.php to generate form elements?.
I have build a form class to generate a form that will allow a
I am trying to write a PHP script that will create an HTML form
I am using a PHP script to generate an email based on the information

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.