Explore the community Forums Lectora Lectora Questions & Answers retrieving the timer value into a variable

Tagged: ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #419738 Score: 0
    Profile photo of KsElement
    KsElement
    Member
    beginner
    intermediate
    friend finder
    curious george
    contributor
    wise owl
    @KsElement

    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?

     

    Thanks,

    Kaye

    #419757 Score: 0
    Profile photo of Adam Cain
    Adam Cain
    Member
    beginner
    intermediate
    profile
    picture perfect
    wise owl
    friend finder
    Group Member
    curious george
    contributor
    17 pts
    @cainam

    Will the reserved variable ‘ElapsedTime’ work for you, or will this timer be starting and stopping?

    #419832 Score: 0
    Profile photo of KsElement
    KsElement
    Member
    beginner
    intermediate
    friend finder
    curious george
    contributor
    wise owl
    @KsElement

    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?

    #419860 Score: 1
    Profile photo of Math Notermans
    Math Notermans
    Member
    contributor
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    LUC16 Attendee
    LUC16
    wise owl
    curious george
    118 pts
    @mnotermans5114

    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”);
    console.log(myText);

    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,
    Math

    This post has received 1 vote up.
    #419889 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    199 pts
    @Klaatu

    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.

    Attachments:
    1. TimerStuff.zip
    #419892 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    199 pts
    @Klaatu

    Another thing you can do is pop your own timer script into Lectora and then have total control over everything.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.