Enter and entry field

Hi, I'm trying to figure out how to make enter functional when using entry fields. I would like a user to type an answer into the entry field, press enter and get the feedback immediately.

Sounds simple, right? But...how can I make it work exactly like that? I'm sure I'm missing something...so heeelp?

undefined

Discussion (13)

Sorry about that. Let me know if you want me to break it down.

Here is a simple example of how a script can easily be used to trigger an action (in this case an action that processes a question) when the Enter key is pressed.

By the way, the answer is sea turtles.

;-)

undefined

this looks like a puzzle without the attachment...:))

but I'm happy someone replied so fast and am looking forward to seeing this solution!!!

Here's the same thing without using jQuery. This is probably the better route in Lectora of the two I suggest.

Hey Darrel, thank you!!...but I don't see how sea turtles 2 are working without jQuery...and I couldn't make it work on my frame.

I guess I'm missing something...probably jQuery knowledge...:))) so I have to try it one more time...but if you have advice how to do it without jQuery that would be really really great!!...

however... if you have advice how to do it without jQuery that would be really really great!!...

undefined3!!

undefined

You could use a standard "On: Keystroke" action. This way you wouldn't need any external JS.

Almost forgot, PageDIV will work for you, however, the action may have a different assignment other than action72.

I had that written up somewhere... Let me see if I can find it.

Yess!! Thank you guys!!

That's exactly what I needed....and it works!

I'm so sorry. I Didn't mean to drag this out. Just in case for some reason I still can't get it right and the post does not work here is the whole thing explained.

Add this script to the page (on show run javascript) that has the entry box you want the enter key to work with.

var thePage = document.getElementById("pageDIV");

thePage.addEventListener("keyup", function(e){

if(e.which == 13) {

action72();

}

});

The first line (var thePage = document.getElementById("pageDIV");) creates a variable called 'thePage' and assigns the HTML element with the ID 'pageDIV' to it. This happens to be the entire page. So in short, thePage equals the page.

Starting on the second line, we add an event listener that will constantly assess whether a key has been let up from the down position (this must mean it was pressed). When it senses any key up happen, it fires off the attached function. The function brings in what triggered it as "e". It is a simple if/then conditional that checks to see if the key up is equal to 13. Thirteen is the ASCII keycode for the enter key. If the key up is the Enter key then it fires off action 72 which is the ID of the lectora action that processes the question.

No jQuery or other HTML extension necessary.

Absolutely go with Tim's offering. Placing an action on the page itself will give you the keystroke action ability. Like he said, you won't have to use JS at all. Trivantis should make a sheet that shows all objects and what actions you can use for each. If it's out there somewhere someone please point me in the right direction; I don't see it in the user guide.

Of course it would be nice to have all actions available to all objects but that's where JS makes this a better application.

@Klaatu

http://community.trivantis.com/forums/topic/triggers/

Very nice, Tim. Thank you for sharing this. It's obvious you put a lot of work into it.

Discussions have been disabled for this post