Use variable in text for droplist

jasonadal
Community Member Posts: 441 ♪ Opening Act ♪
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.
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.
Comments
-
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 -
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? -
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 -
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.
Categories
- 4.7K All Categories
- 3 New Feature Releases
- The Training Arcade®
- Arcades™
- 57 ✫ Announcements
- 6 ✪ Contests
- 34.1K eLearning Brothers® Products
- 33.6K Lectora®
- 31.5K Lectora Discussions
- 1.9K Lectora Feature Requests
- 64 Lectora User Groups
- 16 Asset Library
- 10 AssetLibrary Discussions
- 6 AssetLibrary Feature Requests
- 293 CenarioVR®
- 171 CenarioVR Discussions
- 122 CenarioVR Feature Requests
- 29 Rockstar Learning Platform®
- 20 Rockstar Learning Platform Discussions
- 9 Rockstar Learning Platform Feature Requests
- 4 Off-the-Shelf Course Library
- 3 Off-the-Shelf Course Library Discussions
- 1 Off-the-Shelf Course Library Feature Requests
- 114 CourseMill®
- 107 CourseMill Discussions
- 43 ReviewLink®
- 31 ReviewLink Discussions
- 12 ReviewLink Suggestions
- 2 The Training Arcade®
- 1 The Training Arcade Discussions
- 1 The Training Arcade Feature Requests
- 10 Additional Learning Products
- 2 Adobe®
- 4 Articulate®
- 2 Camtasia®
- Docebo®
- 1 iSpring®
- 1 Microsoft® PowerPoint®
- 912 All Things eLearning
- 5 Course Development Showcase
- 1 eLearning Brothers® Downloads
- 1 Compliance Training
- 11 eLearning Development
- eLearning Game Design
- 7 Instructional Design
- 545 Learning Management System (LMS) Integration
- 2 Mobile Learning
- 5 Visual Design
- 329 Web Accessibility
- 1.2K ♪ The Green Room
- 7 ♡ Community Feedback
- 7 Community Tips