www.webdeveloper.com
Results 1 to 4 of 4

Thread: Javascript calculation does not work

  1. #1
    Join Date
    Dec 2011
    Posts
    13

    Javascript calculation does not work

    Hi Guys,

    I spend hours trying to find the mistake I made, but cannot find it. It is part of a simple accounting thing I m trying to make for the fun of it. What it should do is to add the amount ex vat to the vat amount and put the answer in the next textfield, so it is possible to check by the eye whether the invoice is indeed that amount of money. But, is does not work an I don't know why. Anybody a suggestion? I know I do not validate whether the value is a number or not, but that does not seem to be the problem. I tried the part with another event handler and function which worked. But this part seperatly, nothing.

    Javascript is rather new to me, so I would very much appreciate an explanation why it went wrong.

    Looking forward to a reply.

    The code is as follows:
    Code:
    <html>
    <head>
    <LINK REL=StyleSheet HREF="style.css" TYPE="text/css">
    <script type="text/javascript">
    function transfer_ex()
    {
    var amount_ex = parseFloat(document.getElementById('amount_ex').value) ;
    var vat = parseFloat(document.getElementById('vat').value) ;
    document.getElementById('total_amount').value= amount_ex + vat;
    return;
    }
    </script>
    </head>
    <body>
    <form name = "invoice" action="welcome.php" method="post"><br>
    Amount ex VAT: <input type="text" id="amount_ex" name="amount_ex" value=""  onkeyup=transfer_ex()/><br>
    VAT: <input type="text" id="vat" name="vat" value="" onkeyup=transfer_ex()/><br>
    Invoice amount: <input type="text" id="total_amount" value="-" /><br>
    </form>
    </body>
    </html>
    Looking forward to any reply

    Arie

  2. #2
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Validation Output: 4 Errors
    Line 1, Column 1: no document type declaration; implying "<!DOCTYPE HTML SYSTEM>"
    <html>



    The checked page did not contain a document type ("DOCTYPE") declaration. The Validator has tried to validate with a fallback DTD, but this is quite likely to be incorrect and will generate a large number of incorrect error messages. It is highly recommended that you insert the proper DOCTYPE declaration in your document -- instructions for doing this are given above -- and it is necessary to have this declaration before the page can be declared to be valid.
    Line 13, Column 7: end tag for "HEAD" which is not finished
    </head>



    Most likely, you nested tags and closed them in the wrong order. For example <p><em>...</p> is not acceptable, as <em> must be closed before <p>. Acceptable nesting is: <p><em>...</em></p>

    Another possibility is that you used an element which requires a child element that you did not include. Hence the parent element is "not finished", not complete. For instance, in HTML the <head> element must contain a <title> child element, lists require appropriate list items (<ul> and <ol> require <li>; <dl> requires <dt> and <dd>), and so on.
    Line 16, Column 96: an attribute value must be a literal unless it contains only name characters
    …pe="text" id="amount_ex" name="amount_ex" value="" onkeyup=transfer_ex()/><br>



    You have used a character that is not considered a "name character" in an attribute value. Which characters are considered "name characters" varies between the different document types, but a good rule of thumb is that unless the value contains only lower or upper case letters in the range a-z you must put quotation marks around the value. In fact, unless you have extreme file size requirements it is a very very good idea to always put quote marks around your attribute values. It is never wrong to do so, and very often it is absolutely necessary.
    Line 17, Column 73: an attribute value must be a literal unless it contains only name characters
    VAT: <input type="text" id="vat" name="vat" value="" onkeyup=transfer_ex()/><br>



    You have used a character that is not considered a "name character" in an attribute value. Which characters are considered "name characters" varies between the different document types, but a good rule of thumb is that unless the value contains only lower or upper case letters in the range a-z you must put quotation marks around the value. In fact, unless you have extreme file size requirements it is a very very good idea to always put quote marks around your attribute values. It is never wrong to do so, and very often it is absolutely necessary.
    Line 18, Column 64: NET-enabling start-tag requires SHORTTAG YES
    Invoice amount: <input type="text" id="total_amount" value="-" /><br>



    The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.
    --> http://validator.w3.org/ will help

  3. #3
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Missing quotes
    Code:
    onkeyup="transfer_ex()"
    Use the browser's error console Ctrl+Shift+J

  4. #4
    Join Date
    Dec 2011
    Posts
    13

    Solved; thankx

    The simple removal of a / did the deal + putting the quotation marks

    Thankx a lot, also for the validator. Knew about it, but didn't know it could do this.

    Solved!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles