views:

88

answers:

1

Alright, I know there's a simple way to do this, but it's been years since I've done much javascript

My client has an online order form for event registration (developed by previous web dev.). Currently the order total is just a hidden field:

<INPUT value=78.00 type=hidden name=amount />

But I need the total to calculate based on what date they choose:

<SELECT style="BACKGROUND-COLOR: #ffff99" name=altDate1>
<OPTION value=04/09> Friday, April 9 </OPTION>
<OPTION value=04/14> Wednesday, April 14 </OPTION>
<OPTION value=04/16> Friday, April 16 </OPTION>
<OPTION value=04/19> Monday, April 19 </OPTION>
<OPTION value=04/29> Thursday, April 29 </OPTION>
</SELECT>

This is the javascript that process the form:

<SCRIPT language=Javascript> 

function PaymentButtonClick() {

    document.addform.Product_Name.value = document.Information.StudentLastName.value + ","+ 
                                          document.Information.StudentFirstName.value+","+
                                          document.Information.StudentID.value+","+
                                          document.Information.altDate1.name+","+","+
                                          document.Information.Guests.value+ "," + 
                                          document.Information.StudentType.value;

    document.addform.Product_Code.value = document.Information.StudentID.value;


    if ((document.Information.UCheck.checked==true) &&
        (document.Information.altDate1.value != "") && 
        (document.Information.altDate1.value != "x")) {

        if (document.Information.StudentLastName.value != "" ||
            document.Information.StudentFirstName.value != "" ||
            document.Information.StudentID.value != "" )  {

                document.addform.submit();
        }
        else { 
            alert("Please enter missing information");
        } 
    }
}

</SCRIPT>
A: 

Insert this switch statement into your form processing function:

switch (document.Information.altDate1.value) {
    case '04/09':
        document.Information.amount.value = 78.00;
        break;
    case '04/14':
        document.Information.amount.value = 79.00;
        break;
    case '04/16':
        document.Information.amount.value = 80.00;
        break;
    case '04/19':
        document.Information.amount.value = 81.00;
        break;
    case '04/29':
        document.Information.amount.value = 82.00;
        break;
}
Scott Cranfill
I'm getting this error when I submit the form:Message: 'document.Information.amount' is null or not an objectLine: 193Char: 9Code: 0
miles
Strange. Is that hidden field named "amount" not inside the form named "Information"?
Scott Cranfill
The date select option is in "Information"The hidden input value was in "addform"There's 2 forms on the page, "Information" and "addform action=...>I tried changing the form names in the switch statement you gave me to addform, but got the same error with document.addform.amount.From what I remember, you don't ever need 2 forms on one page. I blame the problems on the genius that had this job before me.
miles
There are occasions you'd need two... but only for completely separate things, like one is an always-present site search field, and the other is a registration form.I'm surprised changing it to `document.addform.amount` didn't work. You could try putting an `id` on the hidden amount field and using `document.getElementById['amount'].value` instead of `document.addform.amount.value`.
Scott Cranfill