Jump to content

Changing a value to an array element


travisco87

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.