lmooring Posted July 15, 2015 Report Share Posted July 15, 2015 I have this existing java script that does a check to see that the net of the invoices entered is equal to the transaction amount entered. I would like to add a condition that this should only execute if the order type is equal to "Pass Thru". Pass Thru is one of three options on a radio button field. Your assistance would be much appreciated! I have attached the existing java script below. Quote Link to comment Share on other sites More sharing options...
iren Posted July 16, 2015 Report Share Posted July 16, 2015 Hello Liz, I am afraid the file with JavaScript is not attached. Could you please post the script to look at it? Quote Link to comment Share on other sites More sharing options...
lmooring Posted July 16, 2015 Author Report Share Posted July 16, 2015 Oh sorry about that and thank you for letting me know. I have copy and pasted the existing script below: <!-- JAVASCRIPTING --> <!-- Calculation script --> <SCRIPT LANGUAGE="JavaScript"> function calculate() { /* Retrieve the value of the field Transaction_Total and store in a variable 'v_trans' */ var v_trans = parseFloat(document.getElementById("InsertRecordVInvoice1Amount").value); /* Retrieve the value of the field Invoice1 and store in a variable 'v_invoice1' */ var v_invoice1 = parseFloat(document.getElementById("InsertRecordTTotal1").value); /* Retrieve the value of the field Invoice2 and store in a variable 'v_invoice2' */ var v_invoice2 = parseFloat(document.getElementById("InsertRecordTTotal2").value); /* Retrieve the value of the field Invoice3 and store in a variable 'v_invoice3' */ var v_invoice3 = parseFloat(document.getElementById("InsertRecordTTotal3").value); /* Retrieve the value of the field Invoice4 and store in a variable 'v_invoice4' */ var v_invoice4 = parseFloat(document.getElementById("InsertRecordTTotal4").value); /* Retrieve the value of the field Invoice5 and store in a variable 'v_invoice5' */ var v_invoice5 = parseFloat(document.getElementById("InsertRecordTTotal5").value); /* Retrieve the value of the field Invoice6 and store in a variable 'v_invoice6' */ var v_invoice6 = parseFloat(document.getElementById("InsertRecordTTotal6").value); /* Retrieve the value of the field Invoice7 and store in a variable 'v_invoice7' */ var v_invoice7 = parseFloat(document.getElementById("InsertRecordTTotal7").value); /* Retrieve the value of the field Invoice8 and store in a variable 'v_invoice8' */ var v_invoice8 = parseFloat(document.getElementById("InsertRecordTTotal8").value); /* Retrieve the value of the field Invoice9 and store in a variable 'v_invoice9' */ var v_invoice9 = parseFloat(document.getElementById("InsertRecordTTotal9").value); /* Retrieve the value of the field Invoice10 and store in a variable 'v_invoice10' */ var v_invoice10 = parseFloat(document.getElementById("InsertRecordTTotal10").value); /* Retrieve the value of the field Invoice11 and store in a variable 'v_invoice11' */ var v_invoice11 = parseFloat(document.getElementById("InsertRecordTTotal11").value); /* Retrieve the value of the field Invoice12 and store in a variable 'v_invoice12' */ var v_invoice12 = parseFloat(document.getElementById("InsertRecordTTotal12").value); /* Retrieve the value of the field Invoice13 and store in a variable 'v_invoice13' */ var v_invoice13 = parseFloat(document.getElementById("InsertRecordTTotal13").value); /* Retrieve the value of the field Invoice14 and store in a variable 'v_invoice14' */ var v_invoice14 = parseFloat(document.getElementById("InsertRecordTTotal14").value); /* Retrieve the value of the field Invoice15 and store in a variable 'v_invoice15' */ var v_invoice15 = parseFloat(document.getElementById("InsertRecordTTotal15").value); /* Add all invoices and freight charged and store in variable v_invtotal */ var v_invtotal = (v_invoice1 + v_invoice2 + v_invoice3 + v_invoice4 + v_invoice5 + v_invoice6 + v_invoice7 + v_invoice8 + v_invoice9 + v_invoice10 + v_invoice11 + v_invoice12 + v_invoice13 + v_invoice14 + v_invoice15); /*Check if v_invtotal = v_trans*/ if ( v_invtotal == v_trans) { /* Insert a value of the variable v_invtotal into the DataPage field Invoice_Total */ document.getElementById("InsertRecordTotalTransaction").value = v_invtotal; } else { alert('Invoice Total does not equal Transaction Totals. Please re-enter values'); } } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Xiang Posted July 19, 2015 Report Share Posted July 19, 2015 Good afternoon Liz, How are you doing? I think, you can enter the following code before the "/*Check if v_invtotal = v_trans*/" line: /* Get the Value of RadioButton field */ var value_rb = document.getElementById("InsertRecordRadioButton2").checked; /* Check if the correct radio button is checked */ if (!value_rb) { alert('ERROR MESSAGE'); return false; } The name "InsertRecordRadioButton2" contains three parts: InsertRecord - prefix, RadioButton - the name of your field; 2 - is the radio button option order, which starts at 0 and increments based on the order of each radio option. For example if your radio button has three options: Incorrect, Wrong, Pass Thru.- Incorrect is InsertRecordFIELDNAME0- Wrong is InsertRecordFIELDNAME1- Pass Thru is InsertRecordFIELDNAME2 Enter your error message instead of "ERROR MESSAGE". I'm learning the JavaScript now, so, I'll be grateful, if you tell me if the code works. Have a nice day! Quote Link to comment Share on other sites More sharing options...
lmooring Posted July 20, 2015 Author Report Share Posted July 20, 2015 Hi Xiang, Thank you for your response. The script did work to determine if the user had checked any of the radio buttons. What I was looking for is to only execute the calculation script if the "pass thru" option specifically was selected. If "donation" or "Store Expense" was selected then the calculation script would not run to compare invoice amount with transaction total. Quote Link to comment Share on other sites More sharing options...
Xiang Posted July 20, 2015 Report Share Posted July 20, 2015 Hi Liz, Oh, it is my fail. I think, now I understand the task better. Could you tell me the order of option for the RadioButton and the name of the field? Or could you provide the URL of your page? Quote Link to comment Share on other sites More sharing options...
lmooring Posted July 20, 2015 Author Report Share Posted July 20, 2015 HI Xiang, The name of the field is OrderType. The options are Pass Thru, Donation, Store Expense. The link to the page is as follows: http://b6.caspio.com/dp.asp?AppKey=87523000c35cff3098294fcd9a59 Quote Link to comment Share on other sites More sharing options...
Xiang Posted July 20, 2015 Report Share Posted July 20, 2015 Hi Liz, You can re-write the followin part of youre code: /*Check if v_invtotal = v_trans*/ if ( v_invtotal == v_trans) { /* Insert a value of the variable v_invtotal into the DataPage field Invoice_Total */ document.getElementById("InsertRecordTotalTransaction").value = v_invtotal; } else { alert('Invoice Total does not equal Transaction Totals. Please re-enter values'); } } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> With the following code: /* Check if the "Pass thru" radio button is selected */ if (document.getElementById("InsertRecordOrderType0").checked) { /*Check if v_invtotal = v_trans*/ if ( v_invtotal == v_trans) { /* Insert a value of the variable v_invtotal into the DataPage field Invoice_Total */ document.getElementById("InsertRecordTotalTransaction").value = v_invtotal; } else { alert('Invoice Total does not equal Transaction Totals. Please re-enter values'); } } else { alert('Please select Pass Thru to continue'); return false; } } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> I'll be grateful, if you tell me if this code works as you want. Quote Link to comment Share on other sites More sharing options...
lmooring Posted July 21, 2015 Author Report Share Posted July 21, 2015 Hi Xiang, The script does work. The only thing is it does not allow for the user to submit an invoice as a Store Expense or a Donation invoice. When the other options are selected the error to go back and select Pass Thru appears. Thank you again for taking time and helping me solve this. Quote Link to comment Share on other sites More sharing options...
Xiang Posted July 21, 2015 Report Share Posted July 21, 2015 Hi Liz, If you want to allow a user submits a record, you can delete the following string: return false; Then the message is displayed, but when a user clicks "Ok", the record is submitted. If you want do not display the message, you can delete the following string as well: alert('Please select Pass Thru to continue'); Quote Link to comment Share on other sites More sharing options...
lmooring Posted July 22, 2015 Author Report Share Posted July 22, 2015 Hi Xiang, I removed the Return false, click OK when the message appears but it then returned that my balances did not equal when my selection was donation. I saved the changes so that you would be able to see the page if you needed to. Quote Link to comment Share on other sites More sharing options...
Xiang Posted July 24, 2015 Report Share Posted July 24, 2015 Hi Liz, I have tried to click Submit and I see different meesages whten different options are selected. Could you please provide expected result, if Pass Thru is selected and if it is not selected? When and what should be displayed? I am afraid, I misunderstand you and propose incorrect Scripts. Quote Link to comment Share on other sites More sharing options...
lmooring Posted August 10, 2015 Author Report Share Posted August 10, 2015 Hi Xiang, Sorry for the delay. I have been out of the office on a trip. I will explain how the page works and the expected results: The store enters all submission information (subname, store# and store name) these fields are not linked to the script. The store selects the vendor name and enters the invoice number. The store then enters the total amount of the invoice in the invoice amount field. The store then needs to select the type of order that was placed. If the store selects "Donation" or "Store Expense" the only other action required is to attach the invoice and submit. There are no corresponding register transactions for these two options and thus the fields remain inactive. The script to check the total of register transactions to invoice amount should not run. Register transactions will always = 0.00 in this case. If the store selects "Pass Thru" the register transaction fields become active and the store is required to enter the transaction information. This is when the script should run to check that the total of the transactions entered is equal to the invoice amount entered in the previous Invoice Amount field. The store then attached the invoice and clicks submit. If the balance is equal the invoice amount the form will submit if not they will get an error message to correct. Thank you for your continued assistance with this. 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.