Cursor focus in orm fields
April 7, 2005 12:00 AM
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.
Discussion (9)
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.
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!
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!
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.
undefined
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.
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 :)
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.
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 undefined IF Question is not empty
I have one of these actions for each question on the page.
I hope this works for you!
@ 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!!!
Discussions have been disabled for this post