tags:

views:

33

answers:

1

I have a string of html that I need to put in an input select but it is out of scope for where the input select is... I think, see that options variable I am building? It needs to be inside the very next select after any of class .product... please advise.

    $(".product").change(function(){

        //get selected option of the select that changed
        var selected = $(this).val();
        //then create the url to reference the value of the selected option (product id)
        var url = "/order/getpricing/" + selected;

        //remove all options from that nearby select statement
        $(this).next('select').children().remove();

        var pricelist = $(this).next('select');

        $.getJSON(url, function(data, pricelist){

            var options = '';
            for(n = 0; n < data.length; n++){
                options += '<option value="' + data[n].volumeID + '">' + explainPricing(data, n) + '</option>';
                //setMeGlobal(options, "options");
                }

                $("#"+pricelist).html(options);


                //TODO NEXT: SOMEHOW ADD OPTIONS TO THE SELECT!


        });

        $(this).next('select').html = options;

    });
+2  A: 

Try re-using the pricelist variable as much as possible. It is automatically available to your ajax handler without you having to pass it around:

$(".product").change(function(){

    //get selected option of the select that changed
    var selected = $(this).val();
    //then create the url to reference the value of the selected option (product id)
    var url = "/order/getpricing/" + selected;

    var pricelist = $(this).next('select');

    //remove all options from that nearby select statement
    pricelist.find('option').remove();

    $.getJSON(url, function(data) {

        var options = '';
        for(n = 0; n < data.length; n++){
            options += '<option value="' + data[n].volumeID + '">' + explainPricing(data, n) + '</option>';
            //setMeGlobal(options, "options");
        }

        pricelist.html(options);
    });
});
Crescent Fresh