Friday, January 13, 2012

Clear Value Prompt Selections Using Javascript

Business Case:
User wants a clickable link on the prompt page to clear all prompt selections.

Environment: Cognos 8.4, Report Studio, Javascript, Mozilla Firefox / Internet Explorer


Implementation:
This can be achieved using Javascript.
  • Place an HTML item at the end of the prompt page after all the prompts.
  • Place the code from the next section into the HTML item.
  • You can use a table to position the link on the page.
  • When the report is executed, user will see a link "Clear All Selections", which will reset all the prompt selections.
Code:
<script>
var list_prompts = document.getElementsByTagName("select");

function ClearSelections(){
  for (var i=0;i<list_prompts.length;i++)
  {
    list_prompts[i].selectedIndex = -1;
  }
}
</script>

<a href="JavaScript:ClearSelections()">Clear All Selections</a>

7 comments:

  1. Thanks for the solution sriram it worked with 8.4 as well as 10.1. Great work.
    Winson.

    ReplyDelete
  2. Hi Sriram,
    This only works for the value from prompt.
    How about if you have a check box value prompt it seems like it does not work with that.
    Could you please post something which will clear the values from the check box multi-select value prompt.
    I will really appreciate it.
    Thanks

    ReplyDelete
    Replies
    1. did you manage to get a solution for the checkbox?

      Delete
  3. How can we make this work for search & select prompt

    ReplyDelete
  4. This is great. Is there a way to modify this code for 2 value prompts. If one value prompt is selective, the other prompt reset/clear.
    I will greatly appreciate it.

    ReplyDelete