Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Member #
    31564
    Guys,

    I have a hopefully small problem. I have a table that I am going to use to enter employee's time into. A dropdown box at the top of the page selects a group of users, which then populates the form. That part works great. For the form itself, I am using arrays to store the information, as in:
    Code:
    echo '<td><input type="text" name="potential[]" size="2"/></td>';
    Now, what I would love, is to have additional columns that do math operations on that row, e.g. a column of applied ratio that divides the hours billed by potential hours.

    What I have tried so far is a simple function as in:
    Code:
    function appliedRatio() {
    var tot = document.time.potential;
    var act = document.time.billable;
    var ar = 100*(parseInt(act.value) / parseInt(tot.value));
    document.getElementById("ar").value = ar;
    However, this pulls data from a specific form element. I'd like to loop over all the form elements, but I'm not quite sure how to go about this. Can I loop over an input array like this? Ideally, I will have a
    Code:
    onchange="applied_ratio();"
    on each form element so everything automatically calculates, but I'm not sure how to get the javascript to loop over all rows of the table and set the values accordingly.

    Thanks

  2.  

  3. #2
    Member Eric Mintz's Avatar
    Join Date
    Mar 2012
    Location
    Atlanta, GA
    Posts
    48
    Member #
    31243
    Liked
    7 times
    Something like this?

    var elementArray = document.getElementById('myForm').elements;
    for(var i = 0; i < elementArray.length; i++) {
    // do stuff with the form elements
    }

    And this?

    var table = document.getElementById('myTable');
    for (var i = 0, row; row = table.rows; i++) {
    // do stuff with rows
    for (var j = 0, col; col = row.cells[j]; j++) {
    // do stuff with cells
    }
    }


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:02 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com