Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Binding: Javascript?

Explorer ,
Jan 13, 2009 Jan 13, 2009
I have an input form set up for financials, and I would like for the subtotals boxes at the bottom to add together whatever the user enters into the text boxes (dynamically). I am using standard text boxes (input instead of cfinput), and I have not set up the form yet (using spry tabs, and when I try to have them all on the same form, they "un-tab" - different subject).
At first I thought I could just bind the subtotal text boxes to the input boxes:
<input id="SubTotal_1" type="text" bind="{Fund1_1}+{Fund1_2}+{Fund1_3}/>
but when I enter numbers in the input boxes, nothing shows up in the subtotal box. Then I though maybe a function would work so I set up a JavaScript function:
<script type="text/javascript">
Function doAdd(a,b,c)
{SumX=a+b+c;
return SumX;}
</script>
When I call the doAdd() function in a button or something, it works, but I want it to be dynamic. Any ideas?
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 13, 2009 Jan 13, 2009
LATEST
I got it. I was having problems passing the field id's as variables, but I FINALLY got it to work. The function is like this:
<script type="text/javascript">
function doAdd(a,b,c,d,e,X)
{
var numVal1=parseInt(document.getElementById(a).value);
var numVal2=parseInt(document.getElementById(b).value);
var numVal3=parseInt(document.getElementById(c).value);
var numVal4=parseInt(document.getElementById(d).value);
var numVal5=parseInt(document.getElementById(e).value);
var totalValue = numVal1+numVal2+numVal3+numVal4+numVal5;
document.getElementById(X).value=totalValue;
}
</script>

And in each text box (except the subtotal box) I have to code this:

onchange="doAdd('Fund1_1','Fund1_2','Fund1_3','Fund1_4','Fund1_5','SubTotal_1b')"

But this works great, now I can use the same function for all of the subtotals on my form. Whoopee!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources