我希望能够使用JavaScript将选择/下拉数据传递到Bootstrap模态框中。我将该模态框用作确认消息。
我的选择/下拉菜单是:
<select class="form-control" id="project" name="project_id">
<option value="1"> ABCD </option>
<option value="2"> EFGH </option>
<option value="3"> IJKL </option>
<option selected="selected" value="#">Please Select</option>
</select>
我正在使用以下Javascript调用Bootstrap模态框:
$('#project').change(function(){
var e = document.getElementById("project");
var p_id = e.options[e.selectedIndex].value;
var p_name = e.options[e.selectedIndex].text;
$('#myModal').modal('show');
});
Bootstrap模态框如下所示:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"></h4>
</div>
<div class="modal-body modal-mt-hgt">
<form action="" method="post">
<p> Are you sure to comment on <b id="p_name">...PROJECT NAME HERE</b> </p>
Enter Your Comment : <textarea rows="3"></textarea>
<input type="hidden" name="country" value="">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Add Task</button>
</div>
<?= form_close(); ?>
</div>
</div>
</div>
我想做的是将变量p_id传递/显示到隐藏字段中,并在模态框的
<b id="p_name"></b>
中显示变量p_name。
进一步说,当用户使用上面的JavaScript函数选择任何选项时,可以获取p_id和p_name,我需要做的唯一事情就是如何在模态框上显示项目名称并将p_id分配给模态框的隐藏字段。
最好的问候