function UpdateTotal() { // CREATING A VARIABLE TO HOLD THE TOTAL AMOUNT var totalAmount = 0; var hasCoupon = 0; // CHECK IF NEW STUDENT if(document.form1.newStudent[0].checked == true) { totalAmount = 20; } // APPLYING THE MULTIPLICATION totalAmount = totalAmount + (document.getElementById('classRate').value * document.getElementById('programLength').value); // CHECK COUPON if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') != "") { if(document.getElementById('classRate')[0].selected == false && document.getElementById('programLength')[0].selected == false) { // COUPON CODE 1 (1 FREE HOUR) if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') == "recordingone") { document.getElementById('couponDescription').innerHTML = '1 FREE hour -- A $30.00 value'; totalAmount = totalAmount - 30.00; document.getElementById('on0').value = document.getElementById('programLength').value + ' day'; document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per session. Coupon Code: recordingone - 1 FREE hour.'; hasCoupon = 1; } // COUPON CODE 2 (2 FREE HOURS) else if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') == "recordingtwo") { document.getElementById('couponDescription').innerHTML = '2 FREE hours -- A $60.00 value'; totalAmount = totalAmount - 60.00; document.getElementById('on0').value = document.getElementById('programLength').value + ' day'; document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per session. Coupon Code: recordingtwo - 2 FREE hours.'; hasCoupon = 1; } // COUPON CODE 3 (5 FREE LESSONS) else if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') == "frtghyu") { document.getElementById('couponDescription').innerHTML = '5 FREE lessons --- A $123.75 value'; totalAmount = totalAmount - 123.75; document.getElementById('on0').value = document.getElementById('programLength').value + ' day'; document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per session. Coupon Code: lesson5 - 5 FREE lessons.'; hasCoupon = 1; } else { document.getElementById('couponDescription').innerHTML = 'Invalid code'; hasCoupon = 0; } } } else { document.getElementById('couponDescription').innerHTML = ' '; } // DISPLAYING THE TOTAL AMOUNT IN THE RIGHT FORM ELEMENT document.getElementById('tot').value = '$' + Dollar(totalAmount); // NOW UPDATE PAYPAL'S FORM document.getElementById('amount').value = Dollar(totalAmount); document.getElementById('on0').value = document.getElementById('programLength').value + ' day'; if(hasCoupon == 0) { document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per session.'; } } // FORM VALIDATION function formValidation() { if(document.getElementById('classRate')[0].selected == true) { alert('Please select the Rate'); document.getElementById('classRate').focus(); return false } if(document.getElementById('programLength')[0].selected == true) { alert('Please select the Length'); document.getElementById('programLength').focus(); return false } if(document.getElementById('os1').value.replace(/^\s*/, '').replace(/\s*$/, '') == "") { alert('Please enter the student name and instrument'); document.getElementById('os1').focus(); return false; } // APPEND THE OPTIONS FIELD FOR THE NEW STUDENT FEE if(document.form1.newStudent[0].checked == true) { document.getElementById('os0').value = document.getElementById('os0').value + ' (+$20 registration fee)' } return true; } function Dollar (val) { // force to valid dollar amount var str,pos,rnd=0; if (val < .995) rnd = 1; // for old Netscape browsers str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape pos = str.indexOf ("."); if (pos > 0) str = str.substring (rnd, pos + 3); return str; }