VVMustang Posted August 16, 2011 Report Share Posted August 16, 2011 Here's another one I'm having trouble making work. I want to ask for a quantity and then fill in the fee based on the quantity answer. If the quantity is 0 the fee will be 0 if the quantity is 4 the fee will be $40. The error is "document.getElementId("EditRecordDirectory_Fee") is null function calculate() { var quantity = parseFloat(document.getElementById("EditRecordDirectory_Quan").value); var price = parseFloat(10); var total = parseFloat(quantity * price); if (quantity == 0) {document.getElementById("EditRecordDirectory_Fee").value = 0;} else {document.getElementById("EditRecordDirectory_Fee").value = Math.round(total);} } document.getElementById("caspioform").onsubmit=calculate; Quote Link to comment Share on other sites More sharing options...
Aariel Posted August 16, 2011 Report Share Posted August 16, 2011 I see that you have provided only one condition in if statement. i.e if (quantity == 0). What happens when quantity is Null?? Therefore, you have to check in a such way that the condition is satisfied if quantity is a number. For example: if(!isNaN(quantity)) {document.getElementById("EditRecordDirectory_Fee").value = 0;} else {document.getElementById("EditRecordDirectory_Fee").value = Math.round(total);} hope it helps... Quote Link to comment Share on other sites More sharing options...
londoncity Posted August 16, 2011 Report Share Posted August 16, 2011 I'd like to see why the "document.getElementId("EditRecordDirectory_Fee") returning Null. where did you put this JS code? make sure you put all your JS codes right before Quote Link to comment Share on other sites More sharing options...
VVMustang Posted August 16, 2011 Author Report Share Posted August 16, 2011 Okay, I made the following modification (see below), with the same error (document.getElementBy....is null). The script is in the footer of the datapage. function calculate_directory() { var quantity = parseFloat(document.getElementById("EditRecordDirectory_Quan").value); var price = parseFloat(10); var total = parseFloat(quantity * price); if(!isNaN(quantity)) {document.getElementById("EditRecordDirectory_Fee").value = 0;} else {document.getElementById("EditRecordDirectory_Fee").value = Math.round(total);} } document.getElementById("caspioform").onsubmit=calculate_directory; 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.