Question subject: getting gst, pst total to diplay in my javascript form
Posted: Thu Jan 26, 2012 2:57 pm
I am working on a javascript form I am having troubles getting the gst, pst and totals to display. I got the subtotal to display but honestly I am not sure how I did it I have changed everything so many times. I would love some input please-- and yes I am really new at this. Thank you to any help anyone can provide.
my Javascript //***************Check for missing information before being able to submit form**************************// function validateForm() { //assume that the form will have no errors. Set a variable to Boolean true. var okay = true; //Declare and initialize a variable to hold a message for the user. var message = ""; //Start at the beginning of the form and check to see if the field is blank or empty string"" if (document.getElementById("FirstName_tf").value == null || document.getElementById("FirstName_tf").value == "") { //The field is empty; set the Boolean variable to false okay = false; message += "Please fill in your First Name.\n"; } if (document.getElementById("LastName_tf").value == null || document.getElementById("LastName_tf").value == "") { //The field is empty; set the Boolean variable to false okay = false; message += "Please fill in your Last Name.\n"; } if (document.getElementById("Address_tf").value == null || document.getElementById("Address_tf").value == "") { //The field is empty; set the Boolean variable to false okay = false; message += "Please enter your Street Address for delivery.\n"; } if (document.getElementById("Phone_tf").value == null || document.getElementById("Phone_tf").value == "") { //The field is empty; set the Boolean variable to false okay = false; if (isNaN(Phone_tf)) { alert(message); message += "Please enter your phone number.\n"; if (document.getElementById("Email_tf").value == null || document.getElementById("Email_tf").value == "") { //The field is empty; set the Boolean variable to false okay = false; message += "Please enter your email address.\n"; } //If the Boolean is no longer true, there were problems with the form. Alert the message. Otherwise, don't do anything. if (!okay) { alert(message); } //return the Boolean. return okay; } function calculateSubtotal(inputItem) { with (inputItem.form) { // Process each of the different input types in the form. if (inputItem.type == "radio") { // Process radio buttons. calculatedSubtotal.value = eval(calculatedSubtotal.value) - eval(radioButton.value); radioButton.value = eval(inputItem.value); calculatedSubtotal.value = eval(calculatedSubtotal.value) + eval(inputItem.value); } else { // Process check boxes. if (inputItem.checked == false) { calculatedSubtotal.value = eval(calculatedSubtotal.value) - eval(inputItem.value); } else { calculatedSubtotal.value = eval(calculatedSubtotal.value) + eval(inputItem.value); } } if (calculatedSubtotal.value < 0) { InitForm(); } function CalculatePrice(){ var gst=.7; var pst=.7; var Subtotal=calculatedSubtotal(); var GST=(Subtotal*gst)*100/100; var PST=(Subtotal*pst)*100/100; document.getElementById(GST_tb)=(Subtotal*GST*PST); //*was trying several thing here but nothing seems to work for me. I got the subtotal by getting the values of the pizza and toppings but can't figure out how to diplay the gst,pst and totals in my html page. } // Return total value. return(formatCurrency(calculatedSubtotal.value)); } }
// Format a value as currency. function formatCurrency(num) { num = isNaN(num) || num === '' || num === null ? 0.00 : num; return parseFloat(num).toFixed(2); }