if function in Java

Discussion in 'Web Design & Coding' started by Goober, Nov 4, 2007.

  1. Goober

    Goober THQ's Jester Moderator

    Joined:
    Jul 26, 2004
    Messages:
    2,864
    Likes Received:
    35
    Location:
    Colorado
    So what I would like to do is have the value in
    Code:
    <INPUT TYPE = Text NAME = taxes SIZE = 6 value ="">
    to display 0 when the check box is unchecked

    As of right now the checkbox (checked or unchecked) will update the total value, which it needs to do.

    Here is EVERYTHING because I'm not sure what you would like to look at.
    Code:
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript" type="text/javascript" src="script1.js"></SCRIPT>  
    <SCRIPT language = JavaScript>
    function calculate() {
    A = document.FrontPage_Form1.book_1.value
    B = document.FrontPage_Form1.book_2.value
    C = document.FrontPage_Form1.book_3.value
    A = Number(A)
    B = Number(B)
    C = Number(C)
    // Subtotal
    D = ((A * 25.99) + (B * 25.99) + (C * 25.99))
    document.FrontPage_Form1.subtotal.value = D
    // Shipping
    E = Math.ceil((A + B + C)/3)
    F = (E * 8.95)
    document.FrontPage_Form1.shipping.value = F
    // Colorado sales tax
    G = (D * .079)
    var num = G;
    var tax = num.toFixed(2);
    document.FrontPage_Form1.taxes.value = tax
    // Total
    H = (D + F)
    if (document.FrontPage_Form1.colo_sales_tax.checked)
    H = (H + G)
    var num = H;
    var result = num.toFixed(2);
    document.FrontPage_Form1.totals.value = result
    }
    </SCRIPT>
    </head>
    <body>
    <form method="POST" name="FrontPage_Form1" onSubmit="return FrontPage_Form1_Validator(this)" target="_self"><font size="2"> 
    <INPUT TYPE = Text NAME = book_1 SIZE = 2 value = ""> Book 1
    <p><INPUT TYPE = Text NAME = book_2 SIZE = 2 value = ""> Book 2</p>
    <p><INPUT TYPE = Text NAME = book_3 SIZE = 2 value = ""> Book 3</p>
    <p><INPUT TYPE = Text NAME = subtotal SIZE = 6 value =""> Subtotal</p>
    <p><INPUT TYPE = Text NAME = taxes SIZE = 6 value =""> <INPUT TYPE = Checkbox NAME = colo_sales_tax value = "">Colorado Residents Check This Box For State Taxes</p>
    <p><INPUT TYPE = Text NAME = shipping SIZE = 6 value =""> Shipping</p>
    <p><INPUT TYPE = Text NAME = totals SIZE = 6 value = "">
    <Input Type = Button NAME = Totals VALUE = "Total" onClick = calculate()></font></p>
    </form>
    </body>
    </html>
    Sorry I'm not a clean coder
     
    Goober, Nov 4, 2007
    #1
    1. Advertisements

  2. Goober

    Goober THQ's Jester Moderator

    Joined:
    Jul 26, 2004
    Messages:
    2,864
    Likes Received:
    35
    Location:
    Colorado
    Update: I got it working, just needed to put the statement in a different place.
     
    Goober, Nov 6, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.