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
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.net/TEjqM/3/
©2020 All rights reserved.