retrieving the timer value into a variable

kselement Community Member Posts: 17
I have a variable that I want to store the Timer value into on, for example mouse-click. How do I retrieve the timer value?





  • cainam
    cainam Community Member Posts: 361 ♦ Idol ♦
    Will the reserved variable 'ElapsedTime' work for you, or will this timer be starting and stopping?
    - Adam Cain
  • kselement
    kselement Community Member Posts: 17
    Thanks for Replying Adam! The timer will be starting and stopping.

    I know how to do this with javascript outside of Lectora, but I am finding it very challenging within Lectora to find the value of an object, whether it be a textbox or a timer. Do you know how I can do this with Javascript inside Lectora?
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916 ☆ Roadie ☆
    Hi Ks,

    First you need some way to select the element. The function given returns the text of a textfield with
    the given css-class.

    var myText  = getText(".someCssClass");

    The function and approach below dont use any extra libraries and still get the text of any given textfield:
    function getText(_cssClass){
    var elem = document.querySelector(_cssClass);// targets a textfield with class someTextfield
    var text = elem.textContent; // target the text content
    return text;


    kind regards,
  • klaatu
    klaatu Community Member Posts: 988
    Yes, you can grab the timer value. See attached. I prefer to use jQuery but it can be accomplished with vanilla JavaScript as well.

    For most objects in Lectora you can get its HTML name by selecting the object going to Properties and then mouse over the little down arrow in the bottom right hand corner in the name box (where you can add a description). However, I find this is not always accurate. I prefer to open the project and use the browsers developers console. From your post, I feel you probably know your way around in there.

    The Timer Object is really only for counting up or down and then performing an action when it completes. There is no reserved variable that holds the current timer object time. The timer object code seems to hold a start time number and last update number and from there calculates the time to pop into a span that displays it but its not assigned a variable you can grab. For this reason it is much easier to just grab the current contents of that span (as I did in the example) and do what you need with it from there. I hope I'm making sense. I need coffee...

    Or you could use Math's suggestion if that works better for you.
  • klaatu
    klaatu Community Member Posts: 988
    Another thing you can do is pop your own timer script into Lectora and then have total control over everything.
  • kjones4547
    kjones4547 Community Member Posts: 34

    How can I modify this to set the timer from the variable?  We have people taking timed exams, and sometimes they get bumped out of the exam or have to get out of the exam.  When they get back in, the timer resets to the full amount of time.  I tried changing it from autostart to play on the first page, but if they get bumped and go back in, the time has reset and doesn't start at all.

    I can see adding the capture action to the next/submit button, but don't know how to make the timer set at the captured time when they go back into the course.

    I don't know JScript or Jquery except for tweaking other's work.


  • carlfink
    carlfink Community Member Posts: 1,102 ✭ Legend ✭
    Karen, thinking outside the box, perhaps ... can your code save the start time on launch, and then just do time arithmetic based on the current time (being triggered, say, every 15 seconds by either an Action or JS timer)? You could easily have your own code update the text field that's part of your Lectora course, too. You'd have to detect midnight, of course.