Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Dynamic populating textfield
System
What is the best way to go about the following scenerio:
In a DCT:
I'm going to create a drop down box which will be populated
by a database
Then depending upon what the user selects - I want that said
value example: <option value="12">Hello</option>
to then be populated in a textfield to create a a href like this:
<a href="/qc?page=Bio&id=12">Hello</a>
What is the best way to do this -
1) using the FORM API only
2) using inline Perl scripts
3) a better way
ANy examples anyone has who has done something similiar would be great
Find more posts tagged with
Comments
jbonifaci
"1) using the FORM API only"
This is definitely the best way if I understand what you're saying.
"2) using inline Perl scripts"
inlines are called when the dcr is loaded, I don't see how this would apply to something the user changes after the initial load.
"3) a better way"
FormAPI is probably the best way to do this and would be fairly simple to implement.
Michael
Hi
Want you want to do sounds quite achievable.
To populate your droplist I would suggest an inline item which calls a script which connects to the database and returns the option items.
To dynamically populate the field with the href I would suggest using formAPI. Register an event onChange of your droplist, the handler of which will get the value and the text of the passed in item and populate your field with the constructed string. If that field is displayed then you will need to refesh at the end.
The code shouldn't be too tricky, but if you get stuck you can always post up another question.
Good luck!
Cheers
Michael
Migrateduser
OK - well I started to code this (using some misc snippets I found in the forums) and I can't seem to get the value from the selectedItem using the Form API - then I'm thinking I can use this temp value to just do a concat and form my URL string! - I attached the DCT for reference as well!
here's my the first snippet from my *.js files:
var key_value="";
function init()
{
IWEventRegistry.addItemHandler("misc", "onItemChange", selectedValue);
selectedValue(IWDatacapture.getItem("misc"));
}
function selectedValue(item)
{
var flag = item.getOptions()[item.getValue()].value != null;
var key = item.getOptions()[item.getValue()].value;
var name = item.getOptions()[item.getValue()].text;
key_value = key;
window.alert(key);
IWDatacapture.redraw();
}
init();
//]]>
Here's the second snippet which didn't give me much either:
//function init()
//{
//IWEventRegistry.addItemHandler("shoes/misc", "onItemChange", getValue);
//getValue(IWDatacapture.getItem("misc"));
//}
//function getValue()
//{
//var index = IWDatacapture.getItem("shoes/misc").getValue();
//var option = IWDatacapture.getItem("shoes/misc").getOptions();
//var value = option[index].value;
// document.write(value);
//}
//init();
DCT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datacapture SYSTEM "datacapture5.0.dtd">
<data-capture-requirements type="content" name="testdct">
<!-- data-capture-requirements elements contain area elements -->
<ruleset name="test">
<description>
A product description
</description>
<item name="misc" rowcontinue="f">
<label>misc</label>
<description></description>
<inline command="d:/iw-home/Interwoven/TeamSite/iw-perl/bin/iwperl.exe d:/iw-home/Interwoven/TeamSite/httpd/iw-bin/inline_get_help_type.ipl"/>
</item>
<item name="pm">
<text required="t" size="40"/>
</item>
<script language="javascript" location="template-type" src="shoescript.js"/>
</ruleset>
</data-capture-requirements>
jbonifaci
What exactly is happening when you change the value of the select? Are you getting a blank alert message? If so, view the source and make sure that your inline is actually outputting values for your options. Your alert should display the value, not the label that the user sees. For a select, the following should get the value:
item.getOptions()[item.getValue()].value
and this should get the label:
item.getOptions()[item.getValue()].text
Migrateduser
When I change the value of the select - nothing happens - my select box is popuated via the inline script fine - however when I make a selection - the value isn't grabbed and the alert doesn't fire -
Must be something very small wrong - because I think all the syntax is OK?
streamserve002.jpg
Migrateduser
I got this working had to add another few lines:
var typeItem = IWDatacapture.getItem("/misc");
var typeIndex = typeItem.getValue();
var name = item.getOptions()[typeItem.getValue()].value;
Thanks - I'm a little rusty I guess in FormAPi - I worked with it pretty in-depth about 6 months - a year ago but forgot some of the little quirks and ins and outs of it