Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:29:55+00:00 2026-05-30T07:29:55+00:00

My goal is to set the focus to a specific inputText. As there seems

  • 0

My goal is to set the focus to a specific inputText.

As there seems to be no way to do this automatically with an tr:inputText property, I try to use Javascript.

For document.getElementById I need the id of the rendered html <input>. I try to set this id to the correct index. However, it is rendered with the id varFieldIterator:0:varField where the number 0 comes from the iterator and is different depending on my start value selectionStart. If I start with selectionStart = 10, the 1st index for the textbox 10 is 0. If I start with 15 and then have a PPR to show the first 15 textboxes, they get the id starting with 16.

I think the code will make clear what I try to achieve:

<tr:iterator
    id="varFieldIterator"
    value="#{myController.form.model.fieldList}"
    var="field"
    rows="15"
    first="#{{myController.form.model.selectionStart}"
    varStatus="status">
  <tr:inputText
      id="varField#{status.index}"
      value="#{field.value}"
      label="Text #{status.index +1}">
</tr:iterator>

<tr:inputHidden
    id="FOCUS_TEXT"
    value="#{myController.form.model.endFocus}"></tr:inputHidden>
<trh:script>
window.onload = function() { document.getElementById('varField' + document.getElementById('FOCUS_TEXT').value).focus(); } 
</trh:script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:29:57+00:00Added an answer on May 30, 2026 at 7:29 am

    While the ID attribute accepts EL expressions, it is only set during view build time, not during view render time. So if you were using a view build time tag such as JSTL <c:forEach> it would have worked. But this tag may have undesireable side effects.

    I’d recommend to just change your JavaScript function so that it does not depend on IDs anymore. It’s unclear what your entire HTML dom structure is and if you’re using jQuery or not which would simplify HTML DOM traversal.

    With plain JS, you could for example just grab the first form and then grab its first input element:

    document.forms[0].elements[0].focus();
    

    Or you could grab input elements by tag name:

    document.getElementsByTagName("input")[0].focus();
    

    Or you could give them all a class name like <tr:inputText styleClass="specificInput"> and grab them by class name:

    document.getElementsByClassName("specificInput")[0].focus();
    

    Those calls are chainable. So if you know that it’s inside a <h:form id="myForm"> then you could also do for example:

    document.getElementById("myForm").getElementsByTagName("input")[0].focus();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal would be to set the profile the same way as in a
I have tried to work this RegEx to set up a goal in GA
When I try to run this in one of my controllers: goal = @user.goals.detect{|g|
How can i get/set the goal value? So that i can also use it
I've set up Google Analytics and three goals. But it seems like each goal
I have the pages that I want to set as a goal in Google
I'm trying to set up integration tests using the AbstractTransactionalJUnit4SpringContextTests base class. My goal
Goal To use a CREATE TYPE statement in HSQLDB 2.0.0 to create a user-defined
Goal: read in the current value of a set of text boxes. if the
GOAL: Declare/set variables in the scope of the function that called the running function.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.