The Zurich release has arrived! Interested in new features and functionalities? Click here for more

UI Page dynamically calculated fields

yundlu316
Kilo Guru

I've created a form using a UI Page and would like some of the fields to dynamically change depending on what is entered in other fields.   For example if a user fills out field A with $100,000 and field B with $25,000, is it possible for field C to dynamically change to $125,000 (A+B) without submitting or reloading the page?   Would that be a client or processing script?

Thanks!

1 ACCEPTED SOLUTION

You do not need onChange client script declaration. Remove everything from the client script section and just copy this


function sum(){


  $('H').value=parseFloat($('D').value)+parseFloat($('G').value);


}


View solution in original post

28 REPLIES 28

Abhinay Erra
Giga Sage

It will be a client script. In your html call a change event and use the function that is defined in the client script.


Hi Abhinay, thanks for your advice.   I'm not too familiar with writing these scripts so please excuse the possible silly questions.   In my UI Page, I've written the following script in the Client Script section:



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


}


   


  var a = g_form.getValue('total_a');  


  var b = g_form.getValue('total_b');


  var c = g_form.getValue('total_c');  


  var d = g_form.getValue('total_d');


  var e = g_form.getValue('total_e');  


  var f = g_form.getValue('total_f');


  var g = g_form.getValue('total_g');  


  var h = parseInt(a) + parseInt(b) + parseInt(c) + parseInt(d) + parseInt(e) + parseInt(f) + parseInt(g) + parseInt(h);  


    g_form.setValue('grand_total',h);


   


}



What I'm hoping is that as a user enters in total_a, total_b, etc, that grand_total dynamically totals these up.   Is my code above correct?   I can't seem to get the grand_total line to change as different values are entered into A through G.



Thanks!


Hi David,



If you're using UI page, you need to add the onchange in your <input> tag and call the function sum() written in your client script.



See below:



<input type="number" id="grand_total"   onchange="sum();"></input>



Client Script:


function sum()


                              {


                              document.getElementById("grand_total").value = parseInt(document.getElementById("total_a").value) + parseInt(document.getElementById("total_b").value) + ....


                              }


Can you post the html section of your UI page.