Search code examples
javascriptjqueryslidernouislider

jquery noUiSlider pass external javascript variable into function


I am using the No.uislider slider in a mortgage calculator. I ned to specify my maximum and minimum values using a variable, as these change dependant on options a person has selected previously.

This is what i have so far but my variable is not working?

my variables are: value_min value_max

    <script>
    // Loan Details
// Amount
$("#sliderBorrowAmt").noUiSlider({
    start: [ value_min ],
    range: {
        'min': value_min,
        'max': value_max
    },
    connect: "lower",
    serialization: {
        lower: [
            new Link({
                target: $("#value"),
                method: "text"
            }),
            new Link({
                target: $("#amount"),
                format: {
                    decimals: 0,
                    thousand: ',',
                    prefix: '',
                    postfix: ''
                }
            })
        ],
        // Default formatting options
        format: {
            decimals: 0,
            thousand: ','
        }

    }
});

Solution

  • Here is the code:

    <script>
    var value_min = 20;//change as per your need
    var value_max = 100;//change as per your need
    
        // Loan Details
    // Amount
    $("#sliderBorrowAmt").noUiSlider({
        start: [ value_min ],
        range: {
            'min': value_min,
            'max': value_max
        },
        connect: "lower",
        serialization: {
            lower: [
                new Link({
                    target: $("#value"),
                    method: "text"
                }),
                new Link({
                    target: $("#amount"),
                    format: {
                        decimals: 0,
                        thousand: ',',
                        prefix: '',
                        postfix: ''
                    }
                })
            ],
            // Default formatting options
            format: {
                decimals: 0,
                thousand: ','
            }
    
        }
    });