Jump to content

Changing a value to an array element


travisco87
Go to solution Solved by kicken,

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.