0

I have included a fiddle here: jsfiddle.net/LgE3N

I have a series of arrays in a javascript file that I need to import into an web page. I seem to be able to work with the arrays in the script and have been able to output totals of numbers into the page, however, I do not seem to be able to figure out how to print the entire list into the web page.

    window.onload = function ()
    {
$("#contributions").html (totalContributions.toFixed(2));
$("#amount").html (totalContributors);  

var dateString = "";
for (var j = 0; j < date.length; j++)
{
    dateString += date[j];
    $("#dateArray").html (dateString);
}
    }

.

    <div id="data_list">
    <table rules="rows" cellspacing='0'>
        <thead>
            <tr>
                <th>Date</th>    
                <th>Amount</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Address</th>
            </tr>
            <td>
                <p>dateArray</p>
                <id "dateArray">
            </td>
            <td>
                <p>amountArray</p>
            </td>
            <td>
6
  • I think you're missing some information. What is "date"? If you could make a Fiddle for this it would make it easier for people to help you. Commented Jun 9, 2014 at 12:41
  • 1
    <id "dateArray"> is not valid html. Change it to <div id="dateArray"></div> Commented Jun 9, 2014 at 12:43
  • when I use div id it puts the date beside the heading in the table. I want the dates to appear as a list underneath each of the headings. Commented Jun 9, 2014 at 12:54
  • Sorry, I do not know what a Fiddle is. On I previous post I was told not to include all code. How much more would be helpful without overdoing it? Commented Jun 9, 2014 at 12:55
  • Go to jsfiddle.net and write your code there. Click the run button to show output. confirm correct output and click save/update. After it saves copy paste the link that gets created from the adress bar over here Commented Jun 9, 2014 at 12:56

1 Answer 1

3

This isn't really hard, you need a loop that returns each row and append it to the table.

var count = firstName.length, sum = 0;

for (var i = 0; i < count; i++) {
    sum += parseFloat(amount[i]);
    html = '<tr><td>'+ date[i] +'</td><td>'+ amount[i] +'</td><td>'+ firstName[i] +'</td><td>'+ lastName[i] +'</td><td><p>'+ street[i] +'<br>'+ city[i] +' '+ state[i] +' '+ zip[i] +'</p></td></tr>';
    $('#data').append(html);
};

$('#contributions').html(count);
$('#amount').html(sum);

DEMO: http://jsfiddle.net/8XvQw/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.