Hi,
I will answer all your questions by separated because would be easier to understand:
Q: So, I can use if condition as above ?
A: Yes, of course there are different ways to use conditional statements.
Using the “IF” operation included by the plugin:
IF(condition, value if condition is true, value if condition is false)
Ternary operator:
(condition) ? value if condition is true : value if condition is false
Conditional statement:
if(condition)
{
statements if condition is true;
}
else
{
statements if condition is true;
}
Important Note: JavaScript is a case sensitive language.
Q: Plugin do have a round function.
A: Yes, the operation ROUND
ROUND(3.4) returns 3
ROUND(3.7) returns 4
Q:Important and will be using with if condition for my project:
Can I do a datepicker like Ex.
Buying Date: 6/7/09 Selling Date: 5/7/15 (or today)
if (sellingdate – buyingdate) < 5 years
take this value —> v1;
else take v2
A: I will use the structure of the fields names in our plugin:
Buying Date: fieldname1
Selling Date: fieldname2
v1: fieldname3
v2: fieldname4
The difference between two dates returns the number of days between them, you simply should modify the operation like follows to get the number of years:
ABS(fieldname2-fieldname1)/365
So, using the different solutions, explained in the first question:
Equation 1:
IF( ABS(fieldname2-fieldname1)/365 < 5, fieldname3, fieldname4 )
Equation 2:
(ABS(fieldname2-fieldname1)/365 < 5) ? fieldname3 : fieldname4
Equation 3:
(function(){
if(ABS(fieldname2-fieldname1)/365 < 5)
{
return fieldname3;
}
else
{
return fieldname4;
}
})()
Best regards.