+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    1

    Simple java script program

    Hi
    I am a beginner in JS and wanted to write a few simple programs to get accustomed with the syntax and logic of this language. One of the simple programs that I intended to write was for calculating the determinant of a grade 2 matrix.
    I have tried since yesterday to understand what's wrong with the program but I just can't figure it out and it seems harder to me since I don't have a compiler like in C++.
    If someone could take a look and point out what's wrong I would greatly appreciate it.
    Here's the code:

    <html>

    <head>
    <title>Calculating 2 grade matrix determinant program</title>

    <script>

    function parseEl (elString) {
    a11 = parseFloat (document.getElementById"a11".value);
    a12 = parseFloat (document.getElementById"a12".value);
    b11 = parseFloat (document.getElementById"b11".value);
    b12 = parseFloat (document.getElementById"b12".value);
    }
    function calcDet () {
    var a11 = parseEl(document.getElementById"a11".value);
    var a12 = parseEl(document.getElementById"a12".value);
    var b11 = parseEl(document.getElementById"b11".value);
    var b12 = parseEl(document.getElementById"b12".value);
    /*if (document.getElementById("a11").value == "")
    alert("Nu ati introdus valoare pentru a11.");
    if (document.getElementById("a12").value == "")
    alert("Nu ati introdus valoare pentru a12.");
    if (document.getElementById("b11").value == "")
    alert("Nu ati introdus valoare pentru b11.");
    if (document.getElementById("b12").value == "")
    alert("Nu ati introdus valoare pentru b12.");
    else */
    det = a11 * b12 - a12 * b11
    alert ("Determinantul este: " + det);
    }
    </script>
    </head>

    <body style="background-color: #777; color: ddd;">
    <div style="margin: 20px;">This program calculates the determinant of a 2 grade matrix</div>
    <form name="Det Matrice">
    <div style="margin-top: 100px; float: left; width: 100%;">
    Enter data:
    <table style="text-align: center;">
    <tr>
    <td><input type="text" id="a11" name="a11" value="a11"></td>
    <td><input type="text" id="a12" name="a12" value="a12"></td>
    </tr>
    <tr>
    <td><input type="text" id="b11" name="b11" value="b11"></td>
    <td><input type="text" id="b12" name="b12" value="b12"></td>
    </tr>
    </table>
    <br>
    </div>
    <div style="float: left; margin-top: 20px;">
    <input type="button" name="Calculate determinant" value="Calculate determinant" onclick="calcDet ();">
    </div>
    </form>

    </body>

    </html>
    Last edited by elfwind; March 4th, 2012 at 09:03 AM.

Quick Reply Quick Reply

If you are already a member, please login above.

What planet do we live on?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Java Script Help
    By machackr in forum Webmastering and Programming
    Replies: 1
    Last Post: April 19th, 2009, 07:10 PM
  2. What Java Script is this?
    By Christato in forum Webmastering and Programming
    Replies: 4
    Last Post: November 28th, 2008, 06:57 PM
  3. Italicizing output for simple Java Program
    By Canadian in forum Webmastering and Programming
    Replies: 6
    Last Post: November 11th, 2005, 07:28 PM
  4. Simple Script
    By Rand Dusing in forum Webmastering and Programming
    Replies: 0
    Last Post: October 14th, 2003, 07:28 PM

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright 2014 All Enthusiast, Inc