CalcBuilder Forum

Conditional Fields (Show/Hide). How to insert additional field-variables?

Usuario moon_1794 2014-09-08 18:45:48

Hello. I am sure there was a message about this, but I cannot find it.

I have the following javascript (taken from one of the examples):

CB('select').change(function(){
// hide divs
CB('#opt1').css('display','none');
CB('#opt2').css('display','none');
// get selected element
var elemSelected=CB(this).find('option:selected').attr('mv_option');
// check to show divs depends on elem selected
if (elemSelected=='opt1') {
CB('#opt1').css('display','block');
}
if (elemSelected=='opt2') {
CB('#opt2').css('display','block');
}
});

Question:

How do I insert additional variables here? Let say I have additional field-variable opt3, opt4, etc.

I have tried to insert another field-variable "opt3" this way:

CB('select').change(function(){
// hide divs
CB('#opt1').css('display','none');
CB('#opt2').css('display','none');
CB('#opt3').css('display','none');
// get selected element
var elemSelected=CB(this).find('option:selected').attr('mv_option');
// check to show divs depends on elem selected
if (elemSelected=='opt1') {
CB('#opt1').css('display','block');
}
if (elemSelected=='opt2') {
CB('#opt2').css('display','block');
}
if (elemSelected=='opt1') {
CB('#opt3').css('display','block');
}
});


But it does not seem to work. Please help, since i would like to make more fields working this way.

Thanks!

Moonsoft support 2014-09-08 18:50:43

Hello,

If you add a new value in combobox named 'opt3' and you want to hide #opt3, there was something missing in if. Try to change:

if (elemSelected=='opt1') {
CB('#opt3').css('display','block');
}

with:

if (elemSelected=='opt3') {
CB('#opt3').css('display','block');
}



Regards,

Usuario moon_1794 2014-09-08 19:10:59

Sorry, this was just a typo.

I have used this:

if (elemSelected=='opt3') {
CB('#opt3').css('display','block');
}


But it does not work the way, the other two variables opt1 and opt2 work.

If you try adding additional variable like "opt3" in "Filtered Sections" example - this will not work. What happen is, the selection field correctly shows all three variable in fron end - it is fine. But when you select third variable from fron end menu - the action which is assigned to it (let say "option list" or "date") does not show up. So, the solution is still pending.

Moonsoft support 2014-09-08 19:19:19

Hello,

We try to add a new 'opt3' in test environment and seems to be working ok. Are in your page any javascript errors? You could post url here or place a ticket in helpdesk and we'll take a look at your site.

Regards,

Usuario moon_1794 2014-09-08 19:30:18

No, there is no any eror message.

Here is the page, where I am testing it:

http://gran....

If you select "Test" from the menu - nothing happens. However for "Test" there is an assignment to show the date is selected.

Edited by moon_1794 - 08.09.2014 19:35

Usuario moon_1794 2014-09-08 19:35:30

I found my mistake. I have had a look into the Form Layout and found out that variable OPT3 was not activated.

So it works fine now.

Thanks.

...
List Manager

Build different lists for your site

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!