Home > WebEOC > Admin Guide > Board Building Tips > Limit Drop-downs to Active Positions

Limit Drop-downs to Active Positions

Table of contents

The following describes how to return a drop-down field that only contains active positions (positions that at least one user is currently logged in to). Specifically, this function analyzes the indicated drop-down field that contains position names and pulls out all positions that begin with an asterisk (*), of which is indicative of a user logged in to that position.

Note: In the instance of when a record is being updated and the current assignee is not logged in, their position name remains in the drop-down because the record was previously assigned to them.

Set Up the Code

The code below is added to an input view and involves two specific aspects: the drop-down field and the code itself. 

The drop-down field is a <select> field that has an ID set. For example: 

<select id="OnlyLoggedIn" name="YourFieldName" list="Positions"/>

The code is a JavaScript function that must be run when the input view is accessed (on load). However, if your view already contains JavaScript that is being executed on load, this function name needs to be included as a part of your existing on load handler.

<script type="text/javascript">
    function updateSelect(){
    var selectobject = document.getElementById("OnlyLoggedIn")
                 for (var i=selectobject.length; i-1&gt;=0; i--)
                   { 
                      if ( selectobject.options[i-1].innerHTML.substring(0,1) != '*' &amp;&amp; selectobject.options[i-1].innerHTML.substring() != '(Select)')
                          {
                               selectobject.remove(i-1);
                          }
                   }
            }
  window.onload = updateSelect;
</script>

If your view already contains an on call function, adjust the code slightly. For example:

<script type="text/javascript">
    function updateSelect(){
    var selectobject = document.getElementById("OnlyLoggedIn")
                 for (var i=selectobject.length; i-1&gt;=0; i--)
                   { 
                      if ( selectobject.options[i-1].innerHTML.substring(0,1) != '*' &amp;&amp; selectobject.options[i-1].innerHTML.substring() != '(Select)')
                          {
                               selectobject.remove(i-1);
                          }
                   }
            }
  window.onload = SetSubmitHandler;  //or some other function name
function SetSubmitHandler()
{
     updateSelect();
     //some of your other JavaScript stuff would be here
}
</script>
You must to post a comment.
Last modified

Tags

Classifications

This page has no classifications.