I'm trying to get this form to finish validating.

Discussion in 'JavaScript' started by GSirtak, Nov 1, 2009.

  1. #1
    Hi,

    I want to put the form on my website to allow customers to calculate their charges. I need for a customer to put total charges in the total charges box.

    The discount special at the time that I'm giving to them. That then sends the amount to the payment area. I would like a prompt telling the client to input a charge if not put in.

    Can I get a helping hand? I would appreciate it.
    Thanks,

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>George Sirtak Javascript Test 2</title>
    <meta http-equiv="content-type" content="text/html;
    charset=iso-8859-1" />
    <link rel="stylesheet" href="js_styles.css" type="text/css" />
    <script type="text/javascript">
    //<![CDATA[


    function calcpay()
    {
    var payment, discount;
    if (document.form.name.value == "")
    {
    alert("You must enter a name");
    document.form.name.focus();
    return false;
    }

    var customerType = false;
    for (var i=0; i<3; ++i) {
    if (document.forms[0].cusType.checked == true) {
    customerType = true;
    break;
    }
    }

    if (customerType != true) {
    window.alert("You must enter a customer Type.");
    return false;
    }


    if (document.form.charge.value == "")
    {
    prompt("Enter a Charge amount");
    document.form.charge.focus();
    return false;
    }

    if (document.form.status.value == 1)
    payment = document.form.charge.value * 10.00;
    else if (document.form.status.value == 2)
    payment = document.form.charge.value * 17.5;
    else if (document.form.status.value == 3)
    payment = document.form.charge.value * 15;
    else
    {
    alert("You must enter a 1, 2, or 3 in the Status Box");
    document.form.status.focus();
    return false;
    }
    discount = payment * .33;
    document.form.discount.value = discount.toFixed(2);
    payment = payment - discount;
    document.form.payment.value = payment.toFixed(2);
    return true;
    }
    /**
    pay = payment * .33;
    document.form.discount.value = charge.toFixed(2);
    payment = payment - pay;
    document.form.pay.value = pay.toFixed(2);
    return true;
    }
    **/
    </script>
    </head>

    <body>
    <fieldset style="width:45%; color:blue">
    <form method="get" name="form" >


    <h1>Charge Information</h1>

    <br /><br />

    Customer's Name:&nbsp&nbsp<input type=text value="" name="name" size=25;>

    <p>Customer Type: <br />
    <input type="radio" name="cusType" value="" />Regular<br />
    <input type="radio" name="cusType" value="" />Silver<br />
    <input type="radio" name="cusType" value="" />Gold<br /><br />
    </p>


    Total Charges:&nbsp&nbsp<input type=text value="" name="charge" size=10;>
    <br /><br />
    Discount:&nbsp&nbsp<input type=text value="" name="discount" size=10;>
    <br /><br />
    Payment:&nbsp&nbsp<input type=text value="" name="payment" size=10;>
    <br /><br />

    <p>
    <input type="button" name="calc" value="Calculate Payment" onClick="return calcpay()">
    <INPUT type="reset" name="Reset" value="Reset">
    </button></p>

    </form>
    </fieldset>
    </body>
    </html>

     
    GSirtak, Nov 1, 2009 IP