VVMustang Posted August 16, 2011 Report Share Posted August 16, 2011 I can't figure out why these three functions aren't working. They only work one at a time. How do I run multiple functions on a .onsubmit? What's the syntax? function calculate() { var quantity = parseFloat(document.getElementById("EditRecordDirectory_Quan").value); var price = parseFloat(10); var total = parseFloat(quantity * price); var quantity2 = parseFloat(document.getElementById("EditRecordBrick_Quan").value); var price2 = parseFloat(50); var total2 = parseFloat(quantity2 * price2); if (document.getElementById('EditRecordGuardian_Membership').checked) {document.getElementById('EditRecordMembership_Fees').value = 15;} else {document.getElementById('EditRecordMembership_Fees').value = 0;} if(isNaN(quantity)) {document.getElementById("EditRecordDirectory_Fees").value = 0;} else {document.getElementById("EditRecordDirectory_Fees").value = Math.round(total);} if(isNaN(quantity2)) {document.getElementById("EditRecordBrick_Fees").value = 0;} else {document.getElementById("EditRecordDirectory_Fees").value = Math.round(total2);} } document.getElementById("caspioform").onsubmit=calculate; Quote Link to comment Share on other sites More sharing options...
londoncity Posted August 18, 2011 Report Share Posted August 18, 2011 Hello VVMustang, Have you tried to create a function to combine all those functions together like this: function cal_all() { calculate1; calculate2; } document.getElementById("caspioform").onsubmit=cal_all; But we should see why the JS you are working on that is not working. :mrgreen: Quote Link to comment Share on other sites More sharing options...
Aariel Posted August 18, 2011 Report Share Posted August 18, 2011 hi VVMustang, I think the way that you are writing your script is correct. One thing you have to make sure is: when you use the fields in javascript, make those fields either 'hidden' or 'text field' or any other 'Form element' . But do NOT make it 'Display only'. Because 'Display only' fields cannot be edited. For debugging your code, you can write alert statement after each if else statement. For eg.: if(..){...}else{...} alert('after first if '); Similarly, you can write for others. If you still have problem, paste the script with alert statement and if the alert is produced or not. Also, install firebug add-on in your Firefox browser. It will show you the javascript error if you have any. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.