Make calculations and update in real time fields

Confluence User - 21 Aug, 2017

Hi Friends,

I have a calculation field named "BONUS" that sum values from a grid form.

Also I take the value from a field named "total_prod" from a sub-form and need make other calculation like "total_prod" - "BONUS" every time that i increase "BONUS". and store this value to Field in the form.

I´m using javascript to get values , but need help to do the calculation and to copy the field in the "Porpagar" field, that is the same as Calculo in the figure bellow.

<script type = "text/javascript" >

var field2 = FormUtil.getField("total_prop");
var b =field2.val();

//Almacenar en Formulario
// FormUtil.getField(Porpagar).val(field2);
$('[name='+Porpagar+']:enabled').val(field2);
//});

</script>

 

 

 

javascript;field;textfield

3


22 Aug, 2017
confluenceUser
confluenceUser

Hi, what is the exact problem that you are facing? Calling the FormUtil.getField(fieldId) will return you the required field element. It is a JQuery element, so you can call .val() to get the value, and val(value) to set the value, as per http://api.jquery.com/val/

 

22 Aug, 2017
confluenceUser
confluenceUser

I think you need to attach event listener to detect changes to the fields you mentioned. Here's quick coding you can start with.

<script type = "text/javascript" >

function updateField(){
	var amount = $(FormUtil.getField("total_prop")).val() - $(FormUtil.getField("total_bonus")).val();

	$(FormUtil.getField("grand_total")).val(amount);

}

$(function(){
 
$(FormUtil.getField("total_prop")).change(function(){
	updateField();
});
 
$(FormUtil.getField("total_bonus")).change(function(){
	updateField();
});
 
});
 
 
</script>

Cheers

27 Aug, 2017
confluenceUser
confluenceUser

Hi Friends, thanks for your answer,

I think that Your code is very weel for my requirement, but in the variable "amount" i get the value NaN, i did decide to evaluate the content of the fields "total_pro" and "total_bonus" witjth te function isNaN () and surprisingly both throw out true As value, what do you think about this?

 

 

This is the definitive code

 

<h3>Nota: Todo abono a la factura será revisado por el departamento de finanzas. .</h3>
<!-- Javascript JQuery to substring string -->

<script type = "text/javascript" >


var field1 = isNaN(FormUtil.getField("total_abonado").val());

function updateField(){
var amount = $(FormUtil.getField("total_prop")).val() - $(FormUtil.getField("total_abonado")).val();

$(FormUtil.getField("porpagar")).val(amount);

}

$(function(){

$(FormUtil.getField("total_prop")).change(function(){
updateField();
});

$(FormUtil.getField("total_abonado")).change(function(){
updateField();
});

});


// To Debug
window.alert(field1);  // This show "TRUE"
// window.alert(a);
window.alert(amount); //This show NaN"
// window.alert(amounts);
// window.alert(5 + 6);
// console.log("x");
// document.write(5 + 6);

//});

</script>

 

 

 

thanks 

fabian

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print