PeterAndrews Posted November 19, 2015 Report Share Posted November 19, 2015 Hi I'm new so sorry if been asked before but I have search and not found anything. I have a submission form that the user uses to enter payments and credits. I want it so if "Payment" is selected then what ever the value in the "amount field" is converted into a minus amount so later on in the reports with the aggregates it calculates the correct sum of payments and credits. thanks Pete Quote Link to comment Share on other sites More sharing options...
Xiang Posted November 23, 2015 Report Share Posted November 23, 2015 Hi Peter, Welcome to the forum! I think, the following code should work: <SCRIPT LANGUAGE="JavaScript"> function calculate() { var fieldAmount = "amount"; var fieldRadioButton = "radiobutton"; var fieldOrder = "1"; fieldRadioButton = "InsertRecord" + fieldRadioButton + fieldOrder; fieldAmount = "InsertRecord" + fieldAmount ; if(document.getElementById(fieldRadioButton).checked) { var currentValue = parseFloat(document.getElementById(fieldAmount).value); if(currentValue>0) { currentValue = currentValue*(-1); document.getElementById(fieldAmount).value = currentValue; } } } document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> Enter names of your fields instead of "amount" and "radiobutton". The "fieldOrder" is the order of the "Payment" option in the radiobutton, the first option is "0"; the second option is "1". 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...
PeterAndrews Posted November 27, 2015 Author Report Share Posted November 27, 2015 Thanks for the response is the code for Header or Footer? <SCRIPT LANGUAGE="JavaScript"> function calculate() { var fieldAmount = "Payamount"; var fieldRadioButton = "Transaction_type"; var fieldOrder = "1"; fieldRadioButton = "InsertRecord" + fieldRadioButton + fieldOrder; fieldAmount = "InsertRecord" + fieldAmount ; if(document.getElementById(fieldRadioButton).checked) { var currentValue = parseFloat(document.getElementById(fieldAmount).value); if(currentValue>0) { currentValue = currentValue*(-1); document.getElementById(fieldAmount).value = currentValue; } } } document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Xiang Posted November 27, 2015 Report Share Posted November 27, 2015 Hi Peter, It's for Footer, and please don't forget to click the "Source" button. 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.