Results 1 to 2 of 2

Thread: what am I doing wrong on this form?

  1. #1
    green9knight Guest

    what am I doing wrong on this form?

    I am trying to adapt a script to work with a more complex problem than it was designed for. It is for my blog. Please help I cant get it to calculate.

    <script language="JavaScript">
    function calculate(Atext,Btext,Ctext,Dtext,E, form) {
    E = [(Atext + Btext)- Ctext] / Dtext;}
    return E;

    var A = parseFloat(Atext);
    var B = parseFloat(Btext);
    var C = parseFloat(Ctext);
    var D = parseFloat(Dtext);


    form.Answer.value = E
    }

    /* ClearForm: this function has 1 argument: form.
    It clears the input and answer fields on the form.
    It needs to know the names of the INPUT elements in order
    to do this. */

    function ClearForm(form)
    {
    form.input_A.value = "";
    form.input_B.value = "";
    form.input_C.value = "";
    form.input_D.value = "";
    form.Answer.value = "";
    }

    // end of JavaScript functions -->
    </script>




    <form name="Calculator" method="post">
    <p>Market Cap: <input type="TEXT" name="input_A" size="10" /></p>
    <p>Debt: <input type="TEXT" name="input_B" size="10" /></p>
    <p>Cash: <input type="TEXT" name="input_C" size="10" /></p>
    <p>EBIT: <input type="TEXT" name="input_D" size="10" /></p>
    <p><input type="button" value="Calculate Numbers" name="AddButton" onclick="CalculateSum(this.form.input_A.value, this.form.input_B.value,this.form.input_C.value,
    this.form.input_D.value,)" /></p>
    <p><input type="button" value="Clear Fields" name="ClearButton" onclick="ClearForm(this.form)" /></p>
    <p>Answer = <input type="TEXT" name="Answer" size="12" /></p>
    </form>

  2. #2
    Join Date
    Jun 2007
    Posts
    295
    There are several huge issues with the form...first, you call the function "calculate", but in the HTML form, you call the function "CalculateSum". so that won't work. Secondly, in the function, you have 5 "options" that need to be included (Atext,Btext,Ctext,Dtext,E, form), but when you call the function in the form, you only give 4 options.

    Next, in the function itself, you end the function after the "E = [(Atext + Btext)- Ctext] / Dtext;" line, so the following code doesn't get executed, and doesn't output anything.

    Also, you have things in the function that have no bearing on anything.

    Code:
    return E;
    This does nothing, since you aren't accessing the function through a variable.

    Code:
    var A = parseFloat(Atext);
    var B = parseFloat(Btext);
    var C = parseFloat(Ctext);
    var D = parseFloat(Dtext);
    While this does something, it's not used anywhere else, so what's the point of this?

    A quick scan of the code blocks shows a myriad of errors. Correct these and see if that doesn't help you.

Similar Threads

  1. Where Have I Gone Wrong?
    By flipjargendy in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 27 Dec 2005, 04:04 PM

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
  •