# Set calculations to have a minimum

• biiainsurance
Asked on January 30, 2014 at 01:13 PM

@Elton helped me with this originally on the calculations ...

I was asked if the "Premium Due" field could display calculated rate or \$350 whichever is greater ....

So far this thing is working like a champ, I finally feel like we are seeing light at the end :o)

Thanks again

• biiainsurance
Answered on January 30, 2014 at 02:09 PM

Wondering ... I found this

variablename=(condition)?value1:value2

and this is the original script from Elton ....

estivalue.onclick = estivalue.onchange = function(){
predue.value = ((ratevalue.value * estivalue.value)/100).toFixed(2);
authonet.value = predue.value;

}

How would I do the comparison ? similar to below ?

estivalue.onclick = estivalue.onchange = function(){
predue.value = ((ratevalue.value * estivalue.value)/100).toFixed(2);
preduegreater.value = (predue.value>350)?"predue.value":"350";
authonet.value = preduegreater.value;

}

Answered on January 30, 2014 at 03:55 PM

I'm a bit confused as to what you are trying to change here now? I see the script Elton gave you but it looks like it was built to do the comparison for this already. Was it not working that well if at all or something? Or may I ask what is the problem that it's doing now that has you are trying to reconfigure more here?

The VARNAME is the variable that holds the values of the entire string. The CONDITION is your function which computes and compares the named 2 VALUES in the programmed equasion to return an answer depending on the outcome of data that is gathered when entered.

• biiainsurance
Answered on January 30, 2014 at 04:02 PM

His script works perfectly ... What i am trying to do now is take the predue.value which is also the authonet.value and see if it is greater that 350. If greater than 350 use the value if less than 350 use the value of 350 ..

Does tha make sense ? Sorry for the confusion ...

• Jeanette
Answered on January 30, 2014 at 05:27 PM

As this is a custom code provided by someone in the Support Staff, I'll pass onto Elton so he can follow up

• biiainsurance
Answered on January 30, 2014 at 05:33 PM

Thank you !

• biiainsurance
Answered on January 30, 2014 at 09:22 PM

I guess this would stem from this post that Elton helped me with

I feel like I almost have the script working but not quite sure the disconnect.

Orignial
#########

estivalue.onclick = estivalue.onchange = function(){
predue.value = ((ratevalue.value * estivalue.value)/100).toFixed(2);
authonet.value = predue.value;

Edited to set value to 350 or value, whichever is greater
#########

estivalue.onclick = estivalue.onchange = function(){
preduegreat.value = ((ratevalue.value * estivalue.value)/100).toFixed(2);
predue.value = (preduegreat.value<350)?"350":"preduegreat.value";
authonet.value = predue.value;
}

• TitusN
Answered on January 30, 2014 at 10:45 PM

Hello,

I have looped in Elton, and he shall respond as soon as he is available.

• EltonCris
Answered on January 31, 2014 at 12:19 AM

@biiainsurance

Your code is right, you just need to remove the .value on preduegreat since you are storing the value on this variable not on an element. There is also no need for double quotes on the number (350) and the variable (preduegreat) in the condition. =)

Here's a working version. (I have bolded the corrected ones).

estivalue.onclick = estivalue.onchange = function(){

preduegreat = ((ratevalue.value * estivalue.value)/100).toFixed(2);

predue.value = (preduegreat < 350) ? 350:preduegreat;

authonet.value = predue.value;

}

Regards!

• EltonCris
Answered on January 31, 2014 at 12:24 AM

You can also replace onchange event with onkeyup to auto-update the values when you releases a key (on the keyboard).

estivalue.onclick = estivalue.onkeyup

• biiainsurance
Answered on January 31, 2014 at 10:59 AM

@Elton Thank you so much !! Works like a charm :o)

Before starting this form I knew nothing about Javascript ... some of it is clicking and some of it I just dont get. You guys have been awesome !!

• Jeanette
Answered on January 31, 2014 at 12:29 PM

Thanks a lot for your feedback towards Elton, he is a very valuable member in our team

Cheers!