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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:56:20+00:00 2026-06-16T19:56:20+00:00

I have a JSF <h:datatable> with two columns. column 1 : <h:outputText> , gets

  • 0

I have a JSF <h:datatable> with two columns.

  • column 1 : <h:outputText>, gets populated from bean data.
  • coulmn 2 : <h:inputText> boxes.

There is a “Total” field outside the table and I want to have it show the total of fields as entered in column2 in realtime. So I did searching around and found out that I need a JavaScript to do this. I am however quite new to JS.

Where I am confused is how to access the value of the input text box. What I have done so far:

function totalFrom() {
    var element = document.getElementById('transferFundsForm:fundsFromTable:0:from_transferAmt');
    if(element != null){
        document.forms['transferFundsForm']['transferFundsForm:totalFrom'].value = document.forms['transferFundsForm']['transferFundsForm:totalFrom'].value+ element;
    }
}

As far as I understand, the transferFundsForm:fundsFromTable:0, here 0 represents the first row. How do I refer to the element in column that is being edited?

I have called this function on onblur event of the textBox in column.

Also I read that I can use <f:ajax> for this as well, but I am using JSP instead of Facelets, so I can’t use <f:ajax>.

  • 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-16T19:56:21+00:00Added an answer on June 16, 2026 at 7:56 pm

    The HTML DOM element representation of <table> element has a rows property which gives you an array of all <tr> elements. The HTML DOM representation of this <tr> element has a cells property which gives you an array of all <td> elements.

    So, provided that the 2nd column of the table contains only one <input> element which holds the value you’d like to sum up, and that totalFrom is an <input> element (at least, you’re attempting to set the value property and not innerHTML), you could achieve this as follows:

    function totalFrom() {
        var table = document.getElementById('transferFundsForm:fundsFromTable');
        var total = 0;
    
        for (var i = 0; i < table.rows.length; i++) {
            var secondColumn = table.rows[i].cells[1];
            var input = secondColumn.getElementsByTagName('input')[0];
            var value = parseInt(input.value);
    
            if (!isNaN(value)) {
                total += value;
            }
        }
    
        document.getElementById('transferFundsForm:totalFrom').value = total;
    }
    

    If the totalFrom is however a <h:outputText id="totalFrom">, then set it as follows instead:

        document.getElementById('transferFundsForm:totalFrom').innerHTML = total;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jsf datatable populated from backing bean ArrayList. Now I need to compare
I have a JSF data table <h:dataTable id=memberTable value=#{bean.pList} border=0 rowClasses=rowEven rowOdd var=item> <h:column
I have jsf page: .... <form jsfc=h:form action=> <h:dataTable value=#{newMusician.strings} var=preferredMusicGenre id=musicGenresSelectTable> <h:column> <h:inputText
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
In a JSF 2.1 wep app, I have a column of a dataTable that
I am using JSF 2.0 and Primefaces 3.4.2, I have a datatable populated using
I have an h:dataTable with data generated from an ArrayList with custom object Result.
I have this line in my jsf page <h:dataTable value=#{customer.getCustomerList()} and in my bean
(Using jsf-2) I have a dataTable with one column which can be edited: <h:column>
I'm using JSF 1.1. I have a JSP page with a .... <t:dataTable id=data

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.