Jump to content

Make A Currency Field Value A Negative - Value


Recommended Posts

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

post-19276-0-79713300-1447948018_thumb.p

 

  

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...