admin管理员组

文章数量:1327581

I have a select dropdown in which whatever is selected I wish to display the name in the jquery dialog that pops up, problem I am having it that it seems to be caching/keeping the previous value and never changing it.

    var scenarioname = '';
    scenarioname = $('#FileUploadScenarioID option:selected').text();


    $('#dialog-module-add').dialog({
        autoOpen: false,
        closeOnEscape: false,
        modal: true,
        resizable: true,
        draggable: true,
        height: 680,
        width: 720,
        title: scenarioname
    });

Yes, I see this article but putting that code in jsfiddle did not seem to give me what I am wanting Passing Variables in jQuery to Change a Dialog Title

I have a select dropdown in which whatever is selected I wish to display the name in the jquery dialog that pops up, problem I am having it that it seems to be caching/keeping the previous value and never changing it.

    var scenarioname = '';
    scenarioname = $('#FileUploadScenarioID option:selected').text();


    $('#dialog-module-add').dialog({
        autoOpen: false,
        closeOnEscape: false,
        modal: true,
        resizable: true,
        draggable: true,
        height: 680,
        width: 720,
        title: scenarioname
    });

Yes, I see this article but putting that code in jsfiddle did not seem to give me what I am wanting Passing Variables in jQuery to Change a Dialog Title

Share Improve this question edited May 23, 2017 at 11:44 CommunityBot 11 silver badge asked Mar 14, 2013 at 23:02 Tom StickelTom Stickel 20.5k6 gold badges116 silver badges115 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Maybe:

$('#FileUploadScenarioID').on('change', function() {
    var title = $(this).find('option:selected').text();
    $('#dialog-module-add').dialog('option','title',title);
});

Perhaps when you change the option within select it's not reassigning the new scenarioname value. What if you added an event handler for the select to reassign scenarioname

var scenarioname = '';
$("#FileUploadScenarioID").change(function () {
    $("#FileUploadScenarioID option:selected").each(function() {
        scenarioname = $(this).val();
    });
    console.log(scenarioname);
});

Got something working here: http://jsfiddle/TEjqM/3/

本文标签: