0

I have a hash "c_failures_all" with some values in it and i am capturing value of selected item from a dropdown list in variable "selVal" using jquery. That "selVal" will act as a key in my hash. The problem is selVal is a jquery variable and if do

c_failures_all[selVal]

throws an error "undefined local variable or method `selVal' for #<#:0x15484300>"

    c_failures_all = {"Amount"=>[5, 4, 8, 7, 6], "Lookup"=>[10, 85, 56, 23, 10], "Advantage"=>[9, 5, 40, 12, 3]}
<script>
         $("#error_error_id").on('change', function(){
        //alert('f')
        var selVal = $("#error_error_id").val();
        if(selVal == "All" || selVal == '')
        {
            options.series = [{name: 'All', data: <%= c_failures_arr %>}]
        }
        else
        {
            options.series = [{name: 'D', data: <%= c_failures_all[selVal] %>}]
        }
        var chart = new Highcharts.Chart(options);
    });
  </script>
0

1 Answer 1

1

in JS, you can create an array to access it later in ruby:

<script>
   var arrayFailures  = <%= c_failures_arr.to_json %>;
   $("#list").on('change', function(){
            var selVal = $("#list").val();
            if(selVal == "All" || selVal == '')
            {
                options.series = [{name: 'All', data: arrayFailures[selVal] }]
            }
            else
            {
                options.series = [{name: 'other', data: [4,7,9,6,2]}]
            }
            var chart = new Highcharts.Chart(options);
        });
<script>

I've not tested it, tell me if it works properly.

Sign up to request clarification or add additional context in comments.

1 Comment

Louis its not working,buddy is there any way i could track down what values arrayFailures[selVal] is returning?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.