rob
Administrator
lets say our form has 3 groups - "select a product" , "product1info" and "product2info"
In the "product" group we have a "product" drop down with the following values:
value label
0 Please select (selected as default)
1 Product 1
2 Product 2
When an option is selected we want to show/hide the corresponding product group.
"product1info" and "product2info" both have their "Show group" option set to "hide" - this hides the group when the form loads
By looking at the list of groups you can see the group id next to it's checkbox, you will need to know this for the javascript code we will add later on. For this example I will say that "product1info" has an ID of 2, and "product2info" has an ID of 3.
In the group "product1info" we have a field called "product 1 label", and in "product2info" we have a field called "product 2 label"
To show/hide the product info groups we need to create a javascript action on the "product" drop down element:
save your element, and view your form, you should just see the product drop down, and when you select an option the corresponding product field will appear
hth
Rob
In the "product" group we have a "product" drop down with the following values:
value label
0 Please select (selected as default)
1 Product 1
2 Product 2
When an option is selected we want to show/hide the corresponding product group.
"product1info" and "product2info" both have their "Show group" option set to "hide" - this hides the group when the form loads
By looking at the list of groups you can see the group id next to it's checkbox, you will need to know this for the javascript code we will add later on. For this example I will say that "product1info" has an ID of 2, and "product2info" has an ID of 3.
In the group "product1info" we have a field called "product 1 label", and in "product2info" we have a field called "product 2 label"
To show/hide the product info groups we need to create a javascript action on the "product" drop down element:
- Edit the "product" element
- select the "Javascript" tab and press "Add Javascript action to element"
- Select "onchange" for the Javascript action and enter this code in the javascript code window:
Code:
//get the current value of the product drop down
var v = this.getValue();
// this is our object that maps the product drop down values (1 & 2) to the group html ids
var groups = {
1:'group2',
2:'group3'
};
//get the html id of the group to show
var groupToShow = groups[v];
//loop over all the groups we defined in the object 'groups'
for (var i in groups ){
//if the current group is the one to show - show it
if(groups[i] == groupToShow){
$( groups[i] ).show();
}else{
//otherwise hide it
$( groups[i] ).hide();
}
}
save your element, and view your form, you should just see the product drop down, and when you select an option the corresponding product field will appear
hth
Rob