Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-23
7
Medium Priority
?
156 Views
Last Modified: 2012-05-11
Greetings,

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.

Sky
0
Comment
Question by:Schuyler Kuhl
7 Comments
 
LVL 2

Expert Comment

by:mhmr
ID: 35202579
can you put some of your code?
0
 

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.

0
 
LVL 3

Expert Comment

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

function Tick12() {
var temp      
 temp=donationtotal

if submode == true {
 temp=donationtotal /12
   }
 chargetotal = temp
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

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

Author Comment

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

This is what I was writing in jquery:

<script>

    $(document).ready(function(){
   
    $('input[name=submode]').click(function(){
        if($(this).is(':checked')){
            $('input[name=chargetotal]').val()= $('input[name=donationtotal]').val()/12;
        }
        else{
           $('input[name=chargetotal]').val()= $('input[name=donationtotal]').val();
        }
    });
   
    });


</script>
0
 

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
}


//-->
</script>


Then on the form field I have this:

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


But nothing happens at all.

Thank you.
0
 
LVL 1

Accepted Solution

by:
mrmikeprogrammer earned 2000 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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

916 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