Reputation: 1
How can I open a model box by jQuery on change of select option?
Upvotes: 0
Views: 5635
Reputation: 218877
Depends on what you mean by "modal box" (or "model box" in the question).
If you're talking about a jQuery UI Dialog, this should do it:
$(document).ready(function() {
// Set the element as a dialog
$('div#modalDialog').dialog({
modal: true,
autoOpen: false
});
// Set the dialog to open when mySelect changes
$('select#mySelect').change(function() {
$('#modalDialog').dialog('open');
});
});
This will, when the DOM has loaded, configure a div
element with the id
"modalDialog" to be a modal dialog and set a listener on the change
event of a select
element with the id "mySelect" to open the dialog.
Upvotes: 1
Reputation: 326
You can sent a listener for the select option change
checkout the example here http://jsfiddle.net/N4EZf/2/
html
<select id="selectMe">
<option value='1'>1</option>
<option value='2'>2</option>
</select>
jquery
alert('ready');
$('#selectMe').change(function() {
alert('Call modal function');
});
Upvotes: 0
Reputation: 1422
onchange = "$('#dialogboxname').dialog('open');"
add the onchange attribute like above^
Upvotes: 0