Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Location
    Philly
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Please help me with this code

    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <!--
    New Perspectives on JavaScript, 2nd Edition
    Tutorial 3
    Case Problem 1

    The Lighthouse
    Author: Franco Ferraiolo
    Date: 1/16/13

    Filename: clist.htm
    Supporting files: lhouse.css, list.js, logo.jpg

    -->
    <title>The Lighthouse</title>
    <link href="lhouse.css" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <script type"text/javascript" src"list.js"></script>
    <script type="text/javascript">
    function amountTotal() { // return sum of values to amount array

    total=0;

    for(var i=0; i<amount.length; i++) { // set variable to 0
    total+=amount[i];
    }
    return total;
    }
    </script>
    </head>

    <body>

    <div id="title">
    <img src="logo.jpg" alt="The Lighthouse" />
    The Lighthouse<br />
    543 Oak Street<br />
    Delphi, KY &nbsp;&nbsp;89011<br/>
    (270) 555-7511
    </div>
    <div id = data_list>
    <script type = text/javascript> // set up variables of rows and cellspaces
    <script type = amountTotal(0)>
    Var Total
    Total = #0
    <table border=’1' rules=’rows’ cellspacing=’0'>
    <tr><th>Date</th><th>Amount</th><th>First Name</th>
    <th>Last Name</th><th>Address</th></tr>

    for i=0; i < amount.length; i++ { // create a loop in counter of variable starting at 0 and increase of 1 increments
    if i%2==0 document.write <tr>
    else document.write <tr class= "yellowrow">
    </tr>

    <td> + date[i] + </td>
    <td class = ’amt’>+amount[i]+</td>
    <td> + firstName[i] + </td>
    <td> + lastName[i] + </td>
    <td>
    street[i] + <br />
    city[i] + state[i] + zip[i])
    </td>
    </tr>
    }
    </table>
    </script>

    </div>

    <div id=totals>
    <script type=text/javascript>
    <table border=’1' cellspacing=’1'>
    <tr><th id=’sumTitle’ colspan=’2'>Summary</th></tr>
    <tr><th>Contributors</th>
    <td> + amount.length + </td></tr>
    <tr><th>Amount</th>
    <td> $ + amountTotal() + </td></tr>
    </table>
    </script>

    </div>

    </body>
    </html>

    </body>
    </html>


    can you help me fix this pleaseeee

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Hard to fix something if you don't tell us a) what it currently does and b) what it's supposed to do. Also you should use code formatting:

    Code:
    <html> [...]

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    To start with you have multiple html and body tags - you should only have one of each of those.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I see a lot of errors.

    <script type = amountTotal(0)>
    Var Total
    Total = #0

    Plus HTML and Javascript mixed up together haphazardly.


    document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

    You certainly say that you suck at Java. You seem to have problems with Javascript as well. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

    BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.
    Last edited by Philip M; 01-17-2013 at 07:55 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •