Explore the community Forums Lectora Lectora Questions & Answers Cursor focus in orm fields

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #251119 Score: 0
    Profile photo of slambie
    slambie
    Member
    @slambie

    Lectora won’t automatically give focus to form elements since this will mess up screen readers for 508.Here is an example title of how to set the focus of a form/question object in an html publish: 2005-04-26_174630_form_stuff.zipThere is a javascript function object called Define setfocus() on the question focus page . It has the following code:function setFocus() {document.entry170form.Entry_field.focus();} Where ‘entry170form’ is the name Lectora gave to the form. In 2005, you can view this in the form’s properties or if using an earlier version of Lectora you will have to publish out and view the source on your page to see what this name is. It will always have the same name for every publish.‘Entry_field’ is the name of the entry field (found in the entry object properties in Lectora) that we wish to give focus to. Make sure that this name does not contain spaces. If it does, replace all spaces with underscores.Once you have re-written the code for your specific form name and entry on that page you will need to add an action that calls this function when the page is loaded. I called it “Setfocus to Entry field” in the example. All this does is onShow/goto web address and our web address is the JavaScript function SetFocus() which we just made.

    #319592 Score: 0
    Profile photo of Vicki
    Vicki
    Member
    beginner
    intermediate
    friend finder
    curious george
    wise owl
    contributor
    picture perfect
    5 pts
    @Vicki

    It has been over 11 years since this question was first asked. Has there been any changes in Lectora (I am using version 16.1.2) to allow you to have the cursor automatically show in an entry field and ready to type?

    Thanks!

    #319608 Score: 1
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    209 pts
    @Klaatu

    11 years and no one answered this? HeHe, only kidding. Here you go.

    document.getElementById(“entry42id”).focus();

    Change “entry42id” to whatever the HTML Name that Lectora provides for your entry field. Make sure you add the “id” (no quotes) as Lectora doesn’t always provide the right HTML Name for working with JavaScript. Leave out the “id” and it wont work.

    Add the above in a Run JavaScript on show of the page your form is on. Viola.

    Attached example is in v12 but it works fine in 16.1.2 as well.

    This post has received 1 vote up.
    Attachments:
    1. Set-Focus.zip
    #319612 Score: 0
    Profile photo of Vicki
    Vicki
    Member
    beginner
    intermediate
    friend finder
    curious george
    wise owl
    contributor
    picture perfect
    5 pts
    @Vicki

    Thank you for your quick response Darrel!

    Question…the page I am working on is like a flash card exercise. I have 12 Fill-in-the-blank questions. You click a button to get the “card” to show. You type in your answer, click submit, then the question hides while feedback appears. If the question was answered correctly, the button is disabled.

    You click another button to show another card.

    Can I apply the fix once to focus on all the entry fields as they appear or do I need to create one for each entry field?

    Thanks!

    #319616 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    209 pts
    @Klaatu

    If I am understanding you correctly you would need to apply the script as the second action of each button. The first will show the card with with the entry field, the second sets focus to the entry field. Make sure the set focus action on the button is targeting the correct entry field. I’d like to hear how you make out.

     

    Oh, if you’re comfortable using jQuery, there may be a more elegant way of handling this using a ‘begins with’ selector but I think the above will work good for you easy enough.

    #319686 Score: 0
    Profile photo of Vicki
    Vicki
    Member
    beginner
    intermediate
    friend finder
    curious george
    wise owl
    contributor
    picture perfect
    5 pts
    @Vicki

    It worked perfectly once I figured out where to put it. I added the action to run the JavaScript to the entry field for each question. Yay!

    Thank you!!!

    Now, is there a way to set the entry field to accept pressing the enter key on your keyboard to submit the question?

    Thanks again!

    I just did a search and found the answer…so nevermind 🙂

    • This reply was modified 4 years, 3 months ago by Profile photo of Vicki Vicki .
    #319730 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    209 pts
    @Klaatu

    Awesome, glad you have everything working!

    #320282 Score: 0
    Profile photo of Elizabeth Dalton
    Elizabeth Dalton
    Member
    beginner
    intermediate
    friend finder
    advanced
    profile
    picture perfect
    Group Member
    contributor
    wise owl
    entry
    2 pts
    @edalton8468

    Hi Vicki, what was the answer to this? I’m looking to set an entry field so that the entry will submit when enter is clicked on keyboard too.

    #321111 Score: 0
    Profile photo of Vicki
    Vicki
    Member
    beginner
    intermediate
    friend finder
    curious george
    wise owl
    contributor
    picture perfect
    5 pts
    @Vicki

    Hi Elizabeth,

    I apologize for the delay in responding. I was out of town for a week then the holiday weekend.

    At the page level, I added an action to:

    On Keystroke <Enter> Process Question <target> IF Question is not empty

    I have one of these actions for each question on the page.

    I hope this works for you!

    #381980 Score: 0
    Profile photo of Roz Schwartz
    Roz Schwartz
    Member
    beginner
    intermediate
    junior moderator
    profile
    entry
    entry
    advanced
    friend finder
    contributor
    wise owl
    13 pts
    @rgs55

    @ Darrel Somoza: You are a lifesaver!! This worked great. Just as a matter of info, I’m using a fill-in-the-blank question (vs. a form and field) and it works fine for that entry field, too. I can now remove that aura of disappointment from my client! LOL.

    Thank you!!!

    • This reply was modified 2 years, 8 months ago by Profile photo of Roz Schwartz Roz Schwartz.
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.