johnny16
johnny16

Reputation:

Cognos 8 Javascript to select values in a multi select list box prompt

I have a multi select list box value prompt in Cognos 8.3.

It contains values:

Adelaide North
Adelaide South
Adelaide East
Adelaide East
Sydney North
Sydney South
Sydney East
Sydney West
etc.

I want to able to add a button onto my prompt page that when clicked, selects predetermined options, such as Adelaide North, South East and West.

For example: An Adelaide button to select Adelaide North, Adelaide South, Adelaide East and Adelaide West, instead of making the user select the 4 choices in the multi-select list box.

Is there a way I can do this? I have named my list box cboFSA in the miscellaneous area of the properties.

Any help much appreciated.

Upvotes: 0

Views: 14408

Answers (1)

Grant Wagner
Grant Wagner

Reputation: 25931

I'm assuming this is a web-based Cognos interface? If so, this should do it for you:

If the name cboFSA is assigned as the ID attribute of the <select> use:

<select size="6" id="cboFSA" multiple="multiple">
<option>Adelaide North</option>
<option>Adelaide South</option>
<option>Adelaide East</option>
<option>Adelaide East</option>
<option>Sydney North</option>
<option>Sydney South</option>
<option>Sydney East</option>
<option>Sydney West</option>
</select>
<input type="button" value="Select all Adelaide" onclick="selectCity('adelaide', 'cboFSA');">
<input type="button" value="Select all Sydney" onclick="selectCity('sydney', 'cboFSA');">
<script type="text/javascript">
function selectCity(city, list) {
    if ('string' === typeof city) {
        city = city.toLowerCase();
        if (document.getElementById) {
            var sel = document.getElementById(list);
            if (sel && (sel = sel.options)) {
                for (var ii = 0, iiLen = sel.length; ii < iiLen; ++ii) {
                    sel[ii].selected = (sel[ii].text.toLowerCase().indexOf(city) !== -1);
                }
            }
        }
    }
}
</script>

If the name cboFSA is assigned as the NAME attribute of the <select> use:

<select size="6" name="cboFSA" multiple="multiple">
<option>Adelaide North</option>
<option>Adelaide South</option>
<option>Adelaide East</option>
<option>Adelaide East</option>
<option>Sydney North</option>
<option>Sydney South</option>
<option>Sydney East</option>
<option>Sydney West</option>
</select>
<input type="button" value="Select all Adelaide" onclick="selectCity('adelaide', 'cboFSA', this);">
<input type="button" value="Select all Sydney" onclick="selectCity('sydney', 'cboFSA', this);">
<script type="text/javascript">
function selectCity(city, list, btn) {
    if ('string' === typeof city) {
        city = city.toLowerCase();
        var sel;
        if (btn && btn.form && (sel = btn.form[list]) && (sel = sel.options)) {
            for (var ii = 0, iiLen = sel.length; ii < iiLen; ++ii) {
                sel[ii].selected = (sel[ii].text.toLowerCase().indexOf(city) !== -1);
            }
        }
    }
}
</script>

You can use View > Source in your browser to figure out whether Cognos assigns the value you specify as the ID or NAME attribute.

Upvotes: 3

Related Questions