If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Set Focus on First Prompt on Prompt Page

Started by raywilliams, 11 Dec 2014 09:49:55 AM

Previous topic - Next topic

raywilliams

Hello! Is it possible to find the first prompt on multiple prompt pages and give each focus, without looking for the specific name of the prompt? I've seen a previous answer that uses javascript that looks for a specific name and then sets the tab index. I was able to use that and it worked perfectly. Now I've been asked to change the javascript so it finds the first prompt over multiple prompt pages. I've had no luck so far. Here's what I used in an HTML item to find a text box on the first prompt page:


<script language="JavaScript" type="text/javascript">

//<!–
var f = getFormWarpRequest();
var tbls = f.getElementsByTagName("INPUT")
var tblCnt = tbls.length;
for(var i=0; i<tblCnt; i++)
{
var tbl = tbls.item(i);
if (tbl.className == "clsTextWidget pt")
{
firstPrompt = tbls[i];
firstPrompt.tabIndex = 1;
}
}
//–>

</script>

<body onLoad="firstPrompt.focus()">


I took the code from http://www.ironsidegroup.com/2011/09/27/ibm-cognos-and-javascript-%E2%80%93-part-ii/. The javascript works on the first page but does NOT work on the second prompt page. I added another HTML item on the bottom of the second page with the same javascript, and used another text box to be sure the classes were the same, in case anyone is wondering.

How do you find the first prompt and give it focus on the second (or more?) prompt page? Thanks for your help!

bdbits

One option is to copy the javascript HTML item, change the name of the prompt control in the javascript to match the new control, and put the script on the second prompt page. A more generic javascript solution will select the first control on a web page. This is not a Cognos-specific thing. A little googling will show you plenty of ways to do that. I'll use this one: http://www.codeproject.com/Articles/11586/Set-Focus-to-First-Input-on-Web-Page

I put his code into an HTML item and wrapped it in a setTimeout. Do the same on each of your prompt pages, or better yet save it with other reusable stuff in an otherwise empty report and use a layout component reference on any prompt page you want to use it with. Note: the timer is to let the page finish loading before focusing. You might need to adjust the timeout (in milliseconds).

<script language="javascript" type="text/javascript">
function myFocusFirst () {
  var bFound = false;
  // for each form
  for (f=0; f < document.forms.length; f++)
  {
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      // if it's not a hidden element
      if (document.forms[f][i].type != "hidden")
      {
        // and it's not disabled
        if (document.forms[f][i].disabled != true)
        {
            // set the focus to it
            document.forms[f][i].focus();
            var bFound = true;
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
  }
}
setTimeout(myFocusFirst,500);

</script>


raywilliams

bdbits, thank you very much. It worked with no issues and no need to adjust the timeout for now. I really appreciate the help! You rock!  8)