简体   繁体   中英

modal appearing when option from select dropdown has been selected

WEll,

I'm trying to make to appear a modal window if one of the options in a select dropdown is selected. It did work if instead of using the option from the select I use a simple button, but I need it from the select.

The screen change it's opacity though, so I guess I'm doing something.... but wrong. Obviously I have the link and scripts from bootstrap that I need, open and close doc and html too.

Any suggestions?

Thank youuu

html
------------------------------------------------------------------------
    <select id="selectAction" data-style="btn-info" onchange="newGraph(this)">
        <option value="" disabled selected>Select your option:</option>
        <option value="create">Create a new graph</option>
        <option value="recall">Recall a saved graph</option>
      </select>

      <!--Pop up window-->

      <div data-toggle="modal" data-target="#popUp1">   //it works if I put this in a <button> instead a div, but then, I have to click to button to make the modal to work so it in not what I want.
<div class="modal hide fade" id="popUp1" tabindex="-1" role="dialog" aria-labelledby="popUp1" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4>Creating a new graph:</h4>
      </div>
      <div class="modal-body">
        <p>Here some text</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-success">Save changes</button>
      </div>
    </div>
  </div>
</div>
    </div> 


script
--------------------------------------------------------------------------------
function newGraph(element) {
  if($(element).val() === 'create') {
     $('.toolsHeader').show();
     $('#popUp1').modal();
      $('#selectAction').hide();
  }
   else{ 
    return false;
  }};

Remove this: onchange="newGraph(this)" from the HTML.

Add this:

$('#selectAction').change(function() {
    newGraph($(this));
});

to the JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM