Explore the community Forums Lectora Lectora Questions & Answers Use variable in text for droplist

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #370724 Score: 0
    Profile photo of Jason Dalrymple
    Jason Dalrymple
    Member
    beginner
    intermediate
    profile
    wise owl
    curious george
    contributor
    friend finder
    advanced
    picture perfect
    44 pts
    @JasonADal

    Is there a way to add a variable as part of an item in a drop list? Using the VAR when entering the text did not work. Looking at the element in the Chrome console, I was able to see the <option value> tag, but haven’t much clue how to change it from flat text to a combination of flat text and the variable.

    Hopefully it’s something simpler than creating a full blown drop down from scratch, as that’s a bit over my head at least for now.

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

    If I am understanding you correctly, you want to have a variable determine the value and text of an option in a drop down, correct? Yup, you can do it (with jQuery).

    $(‘option:nth-child(1)’).attr(‘value’,VarVariable1.getValue()).text(VarVariable1.getValue());

    This will change whatever the first option is (it doesn’t matter) to the value of variable1.

    Darrel

    This post has received 2 votes up.
    Attachments:
    1. Change-Option.zip
    #370745 Score: 0
    Profile photo of Darrel Somoza
    Darrel Somoza
    Member
    contributor
    friend finder
    beginner
    intermediate
    junior moderator
    advanced
    wise owl
    curious george
    profile
    197 pts
    @Klaatu

    By the way, remember that you MUST initialize (use) the variable before it can be manipulated into the select element. Forgot to mention that although my example has it in there.

    #370749 Score: 0
    Profile photo of Jason Dalrymple
    Jason Dalrymple
    Member
    beginner
    intermediate
    profile
    wise owl
    curious george
    contributor
    friend finder
    advanced
    picture perfect
    44 pts
    @JasonADal

    Edit: Is there a way to target just one drop down when there is more than one on the page? A quick google search suggests that I may need to add a class to the drop down to target it with jquery, but I’m not sure I grasp where/how to add the class in the RunJS or if more language is needed.

    I think that will do it, actually – The goal was to have the option read “Text text text <variable value>” In my case, I’m setting a fixed date (assess_date) at the beginning of the course that needs to be added to the end of fixed text. I just fiddled a bit with the sample and think I have the gist enough that I’ll be able to implement.

    Once again, thank you! BTW – did you get my email message?

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

    Yeah,  you can have as many drop downs as you’d like and specifically target any or all of them. Lectora provides class names and ID’s to to each select element so there’s no need to add any of that. You’ll have to append the target by adding additional specificity. I just replied to your email. I would have missed it in hundreds of other emails if you had not mentioned anything. Thank you. Feel free to email me for more on this if you want. I’ll look out for this one.

    Darrel

    #370822 Score: 0
    Profile photo of Jason Dalrymple
    Jason Dalrymple
    Member
    beginner
    intermediate
    profile
    wise owl
    curious george
    contributor
    friend finder
    advanced
    picture perfect
    44 pts
    @JasonADal

    With a little more research, I got it! It was just a matter of learning how to add the element id and whether it needed ‘id’ on the end of the element or not. From there, it was just remembering that I needed the # in front of it, and viola:

    $(‘#combo258138 option:nth-child(2)’).attr(‘value’,VarVariable1.getValue()).text(VarVariable1.getValue());

    Thanks again for all your help and pushing me at least baby steps into the world of JS and jquery.

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

    Awesome. Great job! Keep going.

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

You must be logged in to reply to this topic.