Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Calculate a recurring payment and enter the number into a text field

Posted on 2011-03-23
Last Modified: 2012-05-11

On a credit card transaction form for donations I have a field for donation and a check box for "Break my donation into 12 payments".

So if this check box is checked I'd like to divide the donation by 12 and enter it into the totalcharge field. If it is not checked then the total amount they entered will go into the totalcharge field.

I have had some luck doing similar manipulation in the past with jquery but I am struggling a bit with this one.

Any suggestions will be greatly appreciated.

Thank you.

Question by:Schuyler Kuhl

Expert Comment

ID: 35202579
can you put some of your code?

Author Comment

by:Schuyler Kuhl
ID: 35202685
I have a text field called "donationtotal" and a text field called "chargetotal"  and a check box called submode.

If submode is checked I want to divide donationtotal by 12 and make the result chargetotal. if it is not checked then donationtotal is copied to chargetotal.


Expert Comment

ID: 35202726
just write simple js function on change for Tickbox

function Tick12() {
var temp      

if submode == true {
 temp=donationtotal /12
 chargetotal = temp
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.


Author Comment

by:Schuyler Kuhl
ID: 35202813
yes, this is what I am trying to do.

Author Comment

by:Schuyler Kuhl
ID: 35202833
Sorry i really don't know my syntax properly.

This is what I was writing in jquery:


            $('input[name=chargetotal]').val()= $('input[name=donationtotal]').val()/12;
           $('input[name=chargetotal]').val()= $('input[name=donationtotal]').val();


Author Comment

by:Schuyler Kuhl
ID: 35203351
Ok,  This is my script in the head:

<script language="JavaScript" type="text/javascript">

function CalculateTotal() {

if document.donform.submode.value == true {
 document.donform.chargetotal.value=document.donform.donationtotal.value /12
 document.donform.chargetotal.value = document.donform.donationtotal.value


Then on the form field I have this:

<input name="donationtotal" type="text" size="15" onChange="CalculateTotal()" />

But nothing happens at all.

Thank you.

Accepted Solution

mrmikeprogrammer earned 500 total points
ID: 35218838
You almost have it yourself.  A few minor corrections to your function:
function CalculateTotal() {
  if ( document.donform.submode.checked ) {
    document.donform.chargetotal.value=document.donform.donationtotal.value /12;
  else {
   document.donform.chargetotal.value = document.donform.donationtotal.value

Open in new window

And, if you want to round your divided number to 2 decimal places, then replace the " = document.don.....value/12" with this:
 = Math.round(document.donform.donationtotal.value /12*100)/100

Open in new window

Good luck

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dynamic Dropdowns 15 32
Alert after MVC form submitted 1 22
Page auto-refreshes when scrolled on iPhone. 5 54
WordPress 8 28
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question