Calculate 2 Fields onChange

Isengo 07 Jan, 2015
Hello Folks,
I need some advice with the textfields in CF. I have a really simple Form ( Number 1, Number 2) and I just want to make this calculation:

if (n1<3) { n2*15+n2*25}
else {n2*15+(n2*12*n1)}

I tried to figure out how to load the .js file in my fields, but I guess there was always smth. missing. I am already 6 hours trying, and now I am sick of it. Anyone an advice? I read all the posts about calculate/calculator already, but I think I just misunderstand some main configuration about it.
GreyHead 07 Jan, 2015
Hi Isengo,

What exactly are the field names?

Your example code doesn't actually do anything as it is written? What are the inputs that you want to set?

Do you want to do this in the browser or after the form is submitted?

You can add JavaScript using the Load JavaScript action in the On Load event of your form.

Bob
Isengo 07 Jan, 2015
<div class="form-group gcore-form-row" id="form-row-text1"><label for="text1" class="control-label gcore-label-left">Text Label</label>
<div class="gcore-input gcore-display-table" id="fin-text1"><input name="text1" id="text1" value="" placeholder="" maxlength="" size="" class="validate['number'] form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text" /></div></div><div class="form-group gcore-form-row" id="form-row-text2"><label for="text2" class="control-label gcore-label-left">Text Label</label>
<div class="gcore-input gcore-display-table" id="fin-text2"><input name="text2" id="text2" value="" placeholder="" maxlength="" size="" class="validate['number'] form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text" /></div></div><div class="form-group gcore-form-row" id="form-row-text3"><label for="text3" class="control-label gcore-label-left">Text Label</label>
<div class="gcore-input gcore-display-table" id="fin-text3"><input name="text3" id="text3" value="" placeholder="" maxlength="" size="" class="validate['number'] form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text" /></div></div>



window.addEvent('domready', function () {
    $('text1').addEvent('change', calc);
    $('text2').addEvent('change', calc);
});

function calc() {
    var price = $('text1').value;
    var quantity = $('text2').value;
    $('text3').value = price * quantity;
}


I just copied the code I inserted. Thanks already for your fast reply!
Isengo 07 Jan, 2015

Hi Isengo,

What exactly are the field names?

Your example code doesn't actually do anything as it is written? What are the inputs that you want to set?

Do you want to do this in the browser or after the form is submitted?

You can add JavaScript using the Load JavaScript action in the On Load event of your form.

Bob



Sorry for the second post, cant find an editing button.
I want to do this in the browser, not on submit button. I added the .js code in Setup - onload - Javascript
GreyHead 07 Jan, 2015
Hi Isengo,

And that is working OK ? ? ?

Bob
Isengo 07 Jan, 2015
No sadly it doesnt.

I havent added the code I need yet, just the * multiply - for testing. But even this wont work.
Isengo 07 Jan, 2015
window.addEvent('domready', function () {
    $('text1').addEvent('change', calc);
  
});

  function calc() {
    var price = $('text1').value;    
    $('text3').value = price ;
   }


Even this won't do anything. I am getting really frustrated...

[URL=http://www.bilder-upload.eu/show.php?file=56401f-1420635500.png][IMG]http://www.bilder-upload.eu/thumb/56401f-1420635500.png[/IMG][/URL]


Any Ideas whast it could be?
This topic is locked and no more replies can be posted.