javascript - How to open a Bootstrap Modal on change of select Box - Stack Overflow

I am trying to open a modal on the change event of select Box?This is My Modal<!-- Modal when adding

I am trying to open a modal on the change event of select Box?

This is My Modal

<!-- Modal when adding ment for upload -->
  <div class="modal fade" id="fileUploadModal" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Add Comment</h4>
        </div>
        <div class="modal-body">
          <p><textarea id = "mentsUpload"class="form-control custom-control" rows="3" style="resize:none"></textarea></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" onclick="submitXYX()" data-dismiss="modal">Submit</button>
        </div>
      </div>
    </div>
  </div>

And select Box is:

<select class="selectpicker" id = "selectNEWBox">
    <option value = "1">New</option>
    <option value = "2">Old</option>
    <option value = "3">Scrap</option>
</select>

What I need to do is to open the Modal on change event of select Box.

What I have tried

In $(document).ready(function () {});

Approach 1

$("#selectNEWBox").change(function(){
    $('#fileUploadModal').modal({
    show: true
  });
});

Approach 2

$("#selectNEWBox").change(function (){
    $('#fileUploadModal').modal('show');
});

but these are not working.

Am I missing something?

I am trying to open a modal on the change event of select Box?

This is My Modal

<!-- Modal when adding ment for upload -->
  <div class="modal fade" id="fileUploadModal" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Add Comment</h4>
        </div>
        <div class="modal-body">
          <p><textarea id = "mentsUpload"class="form-control custom-control" rows="3" style="resize:none"></textarea></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" onclick="submitXYX()" data-dismiss="modal">Submit</button>
        </div>
      </div>
    </div>
  </div>

And select Box is:

<select class="selectpicker" id = "selectNEWBox">
    <option value = "1">New</option>
    <option value = "2">Old</option>
    <option value = "3">Scrap</option>
</select>

What I need to do is to open the Modal on change event of select Box.

What I have tried

In $(document).ready(function () {});

Approach 1

$("#selectNEWBox").change(function(){
    $('#fileUploadModal').modal({
    show: true
  });
});

Approach 2

$("#selectNEWBox").change(function (){
    $('#fileUploadModal').modal('show');
});

but these are not working.

Am I missing something?

Share Improve this question edited Mar 29, 2017 at 14:23 Tareque Md Hanif 873 silver badges14 bronze badges asked Mar 29, 2017 at 13:37 Geek_To_LearnGeek_To_Learn 1,9767 gold badges29 silver badges51 bronze badges 8
  • any error you received in console ? – RAJNIK PATEL Commented Mar 29, 2017 at 13:41
  • Other than a missing semicolon at the end '.modal('show')', your code seems to be ok. Can you provide a working fiddle of the issue. – Dan Philip Bejoy Commented Mar 29, 2017 at 13:42
  • works fine: codeply./go/hMooZk56uc – Carol Skelly Commented Mar 29, 2017 at 13:43
  • 1 have you add bootstrap js and css library ?? – RAJNIK PATEL Commented Mar 29, 2017 at 13:45
  • did you load jquery: because your code works - fiddle – birdspider Commented Mar 29, 2017 at 13:46
 |  Show 3 more ments

2 Answers 2

Reset to default 1

just tried your code and it seem working

$( "#selectNEWBox" ).change(function() {
  $('#fileUploadModal').modal('show')
});

try it here

Finally resolved the issue. It seems the issue was because of conflict of Jquery versions.

Removed the conflict and it's working now. :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745590058a4634778.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信