travisco87 Posted December 4, 2013 Share Posted December 4, 2013 So I have found a slider I would like to use in a program but I cannot figure out a certain issue with accessing the information from an array. Here is the code (jQuery) is used FYI with a "slide pips" plugin. <script> $(document).ready(function(){ var emotions = ['Confused', 'Annoyed', 'Angry', 'Concerned', 'Sad', 'Sarcastic', 'Joking', 'Playful', 'Romantic', 'Grateful', 'Awesome', 'Happy', 'Neutral'] $('#defaultslide').slider({ max: 13, min: 1, value: 7, slide: function(e,ui) { $('#currentval').html(ui.value); } }).slider('pips', { first: 'label', last: 'label', rest: 'label', labels: ['Confused', '<br />Annoyed', 'Angry', '<br />Concerned', 'Sad', '<br />Sarcastic', 'Joking', '<br />Playful', 'Romantic', '<br />Grateful', 'Awesome', '<br />Happy', 'Neutral'], prefix: '', suffix: '' }); }); </script> What I want to happen is when the slider moves, the #currentval would need to take the value of the slider and access the array of "emotions" and display the correct string with the value. I tried this slide: function() { $('#currentval').html(emotion[value -1]); } But this did not work. I have tried a couple other variations but nothing is working. What do I need to make the #currentval reference the "emotions" array according to the value of the slider? Link to comment https://forums.phpfreaks.com/topic/284533-changing-a-value-to-an-array-element/ Share on other sites More sharing options...
kicken Posted December 4, 2013 Share Posted December 4, 2013 I'm not familiar with this plugin but just as a wild guess based on the code you posted: slide: function(e,ui) { $('#currentval').html(emotions[ui.value-1]); } Link to comment https://forums.phpfreaks.com/topic/284533-changing-a-value-to-an-array-element/#findComment-1461287 Share on other sites More sharing options...
travisco87 Posted December 4, 2013 Author Share Posted December 4, 2013 Thank you so much! WoW such a simple mistake of the s at the end. Link to comment https://forums.phpfreaks.com/topic/284533-changing-a-value-to-an-array-element/#findComment-1461291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.