Hello, I am fairly new to template building, and I'm trying to create a drop down list (3 item in it) which acts as a trigger to either show/hide a text field.
I've writte some JavaScript which I'm including in my datapcapture.cfg, but the code is written in a way to only show the text field for the 1st replicant item. I've tried a FOR LOOP, but I'm getting errors.
Here's a code snippet:
*container name="MenuGroup" location="MenuGroup" combination="AND" hide-name="t" min="1" max="2">
*item name="MenuTitle">
*label>Menu Title*/label>
*text required="t" size="50">*/text>
*/item>
*container name="MenuItem" location="MenuItem" min="1" max="10" combination="AND" hide-name="t">
*label>Body Section*/label>
*item name="LinkType" pathid="LinkType">
*label>Link Type
*select required="f" multiple="f">
*option value="alert" label="alert"/>
*option value="new" label="new"/>
*option value="update" label="update"/>
*/select>
*/item>
*item name="LinkTest" pathid="LinkTest">
*label>Test*/label>
*text required="f" size="50">*/text>
*/item>
*/container>
Here's the JavaScript I wrote:
*script language="JavaScript">
function init(){
//Add the ItemHandler for the item /BodyContent/Section
IWEventRegistry.addItemHandler("/MenuGroup/MenuItem/LinkType", "onItemChange", toggleContainer);
toggleContainer(IWDatacapture.getItem("/MenuGroup/MenuItem/LinkType"));
}
function toggleContainer(item) {
//Hide fields
//var containerTest = item.getOptions()[item.getName()].value;
//alert(containerTest);
var containerTrigger = item.getOptions()[item.getValue()].value == "alert";
var containerToTrigger = IWDatacapture.getItem("/MenuGroup[1]/MenuItem[1]/LinkTest");
if (containerToTrigger) {
containerToTrigger.setVisible(containerTrigger);
}
else { alert("Cannot find container."); }
}
IWEventRegistry.addFormHandler("onFormInit", init);
*/script>
I know it's only toggling the first item due to the [1] brackets, but how can I creatively/dynamically code this to work on replicant X?
THANK YOU!
Also, this is my first post, so if I'm doing something wrong, please let me know!
How can I paste code into a thread without replacing all "<" with "*"?