js code to show/hide button element not working

vinia

Member
Hi.

Can't get this to work.. :(

var vtotmm2015= document.getElementById('itemarnd2_parent___totmm2015').getValue();
var vtotmm2014= document.getElementById('itemarnd2_parent___totmm2014').getValue();
var btnymmdec= Fabrik.getBlock('form_1').formElements.get('itemarnd2_parent___SET_OF_ymmsqdec_grp');

if (vtotmm2015<=vtotmm2014)
{
btnymmdec.show();
}
else if (vtotmm2015>vtotmm2014)
{
btnymmdec.hide();
}

Am trying to hide a button element based on the values of these two variables variables. Code doesn't work :( Help, please..

TIA,

Vinia
 
What site template do you use? I just found an issue with Bootstrap 3 templates which prevents the hide() / show() functions from working at all, which I just fixed locally and will commit to github soon.

Other than that, it's always best to use the Fabrik objects to get the values, not the DOM elements ... and if you want to do numeric comparisons on values (which are always going to be strings), you need to cast them to numbers ...

Code:
var form = Fabrik.getBlock('form_1');
var vtotmm2015= form.formElements.get('itemarnd2_parent___totmm2015').getValue();
var vtotmm2014= form.formElements.get('itemarnd2_parent___totmm2014').getValue();
var btnymmdec= form.formElements.get('itemarnd2_parent___SET_OF_ymmsqdec_grp');

if (parseInt(vtotmm2015) <= parseInt(vtotmm2014))
{
   btnymmdec.show();
}
else
{
   btnymmdec.hide();
}

If you values are going to be decimals, use parseFloat(). If they may be empty, you'll need to add some code to test for that, otherwise the parseInt/Float will throw a "NaN" (Not a Number) error.

-- hugh
 
Protostar boostrap tabs (Joomla 3.6.5) Thank you sou much for all the help and the pointers, Hugh. It's working now. :) <3
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top