Displaying popup with flask and jquery












-1














on my website after clicking button I want to display new form which will allow users to add opinion. Im not sure in which way I should add jquery script to my project. I tried to it on simple html site and it works, but I couldnt do the same with flask app. Here is my code:



% extends "bootstrap/base.html" %}

{% block content %}

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis.com ajax/libs/jquery/1/jquery.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
<script type="text/javascript">

$(function () {
$("#btnclick").click(function () {
$("#divpopup").dialog({
title:"Dodaj opinie",
width: 430,
height: 200,
modal:true,
buttons: {
Close:
function(){
$(this).dialog('close');
}
}
});

});
})




<div id="divpopup" style="display: none">
Here will be form
</div>

<button type="button" id="btnclick">Add opinion</button>

{% endblock %}


And after clicking on the button nothing happend. I use bootstrap and jinja2, so should I use other contents to add scripts?










share|improve this question





























    -1














    on my website after clicking button I want to display new form which will allow users to add opinion. Im not sure in which way I should add jquery script to my project. I tried to it on simple html site and it works, but I couldnt do the same with flask app. Here is my code:



    % extends "bootstrap/base.html" %}

    {% block content %}

    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
    <script src="http://ajax.googleapis.com ajax/libs/jquery/1/jquery.js"></script>

    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
    <script type="text/javascript">

    $(function () {
    $("#btnclick").click(function () {
    $("#divpopup").dialog({
    title:"Dodaj opinie",
    width: 430,
    height: 200,
    modal:true,
    buttons: {
    Close:
    function(){
    $(this).dialog('close');
    }
    }
    });

    });
    })




    <div id="divpopup" style="display: none">
    Here will be form
    </div>

    <button type="button" id="btnclick">Add opinion</button>

    {% endblock %}


    And after clicking on the button nothing happend. I use bootstrap and jinja2, so should I use other contents to add scripts?










    share|improve this question



























      -1












      -1








      -1







      on my website after clicking button I want to display new form which will allow users to add opinion. Im not sure in which way I should add jquery script to my project. I tried to it on simple html site and it works, but I couldnt do the same with flask app. Here is my code:



      % extends "bootstrap/base.html" %}

      {% block content %}

      <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
      <script src="http://ajax.googleapis.com ajax/libs/jquery/1/jquery.js"></script>

      <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
      <script type="text/javascript">

      $(function () {
      $("#btnclick").click(function () {
      $("#divpopup").dialog({
      title:"Dodaj opinie",
      width: 430,
      height: 200,
      modal:true,
      buttons: {
      Close:
      function(){
      $(this).dialog('close');
      }
      }
      });

      });
      })




      <div id="divpopup" style="display: none">
      Here will be form
      </div>

      <button type="button" id="btnclick">Add opinion</button>

      {% endblock %}


      And after clicking on the button nothing happend. I use bootstrap and jinja2, so should I use other contents to add scripts?










      share|improve this question















      on my website after clicking button I want to display new form which will allow users to add opinion. Im not sure in which way I should add jquery script to my project. I tried to it on simple html site and it works, but I couldnt do the same with flask app. Here is my code:



      % extends "bootstrap/base.html" %}

      {% block content %}

      <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
      <script src="http://ajax.googleapis.com ajax/libs/jquery/1/jquery.js"></script>

      <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
      <script type="text/javascript">

      $(function () {
      $("#btnclick").click(function () {
      $("#divpopup").dialog({
      title:"Dodaj opinie",
      width: 430,
      height: 200,
      modal:true,
      buttons: {
      Close:
      function(){
      $(this).dialog('close');
      }
      }
      });

      });
      })




      <div id="divpopup" style="display: none">
      Here will be form
      </div>

      <button type="button" id="btnclick">Add opinion</button>

      {% endblock %}


      And after clicking on the button nothing happend. I use bootstrap and jinja2, so should I use other contents to add scripts?







      javascript jquery twitter-bootstrap jquery-ui






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 16:59









      davidism

      62.1k12157176




      62.1k12157176










      asked Nov 19 '18 at 15:51









      Frendom

      266




      266
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You might consider using a Bootstrap Modal for this as you said you're using Bootstrap in the project.



          This is a very simple example copied from their website:



          <!-- Button trigger modal -->
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
          Launch demo modal
          </button>

          <!-- Modal -->
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
          <div class="modal-content">
          <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          </button>
          </div>
          <div class="modal-body">
          INSERT FORM HERE
          </div>
          <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
          </div>
          </div>
          </div>
          </div>


          If you're using Bootstrap 4 you should be able to copy this right in and change the IDs to match what you want.
          Link to documentation: https://getbootstrap.com/docs/4.0/components/modal/






          share|improve this answer





















          • Ok, it works. Now I have to look for soma AJAX magic to send information to database
            – Frendom
            Nov 19 '18 at 17:43










          • Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
            – Caleb Lawrence
            Nov 19 '18 at 17:46












          • Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
            – Caleb Lawrence
            Nov 19 '18 at 17:47










          • Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
            – Frendom
            Nov 19 '18 at 17:51










          • Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
            – Caleb Lawrence
            Nov 19 '18 at 17:55











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378260%2fdisplaying-popup-with-flask-and-jquery%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You might consider using a Bootstrap Modal for this as you said you're using Bootstrap in the project.



          This is a very simple example copied from their website:



          <!-- Button trigger modal -->
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
          Launch demo modal
          </button>

          <!-- Modal -->
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
          <div class="modal-content">
          <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          </button>
          </div>
          <div class="modal-body">
          INSERT FORM HERE
          </div>
          <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
          </div>
          </div>
          </div>
          </div>


          If you're using Bootstrap 4 you should be able to copy this right in and change the IDs to match what you want.
          Link to documentation: https://getbootstrap.com/docs/4.0/components/modal/






          share|improve this answer





















          • Ok, it works. Now I have to look for soma AJAX magic to send information to database
            – Frendom
            Nov 19 '18 at 17:43










          • Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
            – Caleb Lawrence
            Nov 19 '18 at 17:46












          • Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
            – Caleb Lawrence
            Nov 19 '18 at 17:47










          • Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
            – Frendom
            Nov 19 '18 at 17:51










          • Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
            – Caleb Lawrence
            Nov 19 '18 at 17:55
















          0














          You might consider using a Bootstrap Modal for this as you said you're using Bootstrap in the project.



          This is a very simple example copied from their website:



          <!-- Button trigger modal -->
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
          Launch demo modal
          </button>

          <!-- Modal -->
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
          <div class="modal-content">
          <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          </button>
          </div>
          <div class="modal-body">
          INSERT FORM HERE
          </div>
          <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
          </div>
          </div>
          </div>
          </div>


          If you're using Bootstrap 4 you should be able to copy this right in and change the IDs to match what you want.
          Link to documentation: https://getbootstrap.com/docs/4.0/components/modal/






          share|improve this answer





















          • Ok, it works. Now I have to look for soma AJAX magic to send information to database
            – Frendom
            Nov 19 '18 at 17:43










          • Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
            – Caleb Lawrence
            Nov 19 '18 at 17:46












          • Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
            – Caleb Lawrence
            Nov 19 '18 at 17:47










          • Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
            – Frendom
            Nov 19 '18 at 17:51










          • Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
            – Caleb Lawrence
            Nov 19 '18 at 17:55














          0












          0








          0






          You might consider using a Bootstrap Modal for this as you said you're using Bootstrap in the project.



          This is a very simple example copied from their website:



          <!-- Button trigger modal -->
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
          Launch demo modal
          </button>

          <!-- Modal -->
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
          <div class="modal-content">
          <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          </button>
          </div>
          <div class="modal-body">
          INSERT FORM HERE
          </div>
          <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
          </div>
          </div>
          </div>
          </div>


          If you're using Bootstrap 4 you should be able to copy this right in and change the IDs to match what you want.
          Link to documentation: https://getbootstrap.com/docs/4.0/components/modal/






          share|improve this answer












          You might consider using a Bootstrap Modal for this as you said you're using Bootstrap in the project.



          This is a very simple example copied from their website:



          <!-- Button trigger modal -->
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
          Launch demo modal
          </button>

          <!-- Modal -->
          <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
          <div class="modal-content">
          <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          </button>
          </div>
          <div class="modal-body">
          INSERT FORM HERE
          </div>
          <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
          </div>
          </div>
          </div>
          </div>


          If you're using Bootstrap 4 you should be able to copy this right in and change the IDs to match what you want.
          Link to documentation: https://getbootstrap.com/docs/4.0/components/modal/







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 16:24









          Caleb Lawrence

          48128




          48128












          • Ok, it works. Now I have to look for soma AJAX magic to send information to database
            – Frendom
            Nov 19 '18 at 17:43










          • Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
            – Caleb Lawrence
            Nov 19 '18 at 17:46












          • Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
            – Caleb Lawrence
            Nov 19 '18 at 17:47










          • Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
            – Frendom
            Nov 19 '18 at 17:51










          • Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
            – Caleb Lawrence
            Nov 19 '18 at 17:55


















          • Ok, it works. Now I have to look for soma AJAX magic to send information to database
            – Frendom
            Nov 19 '18 at 17:43










          • Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
            – Caleb Lawrence
            Nov 19 '18 at 17:46












          • Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
            – Caleb Lawrence
            Nov 19 '18 at 17:47










          • Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
            – Frendom
            Nov 19 '18 at 17:51










          • Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
            – Caleb Lawrence
            Nov 19 '18 at 17:55
















          Ok, it works. Now I have to look for soma AJAX magic to send information to database
          – Frendom
          Nov 19 '18 at 17:43




          Ok, it works. Now I have to look for soma AJAX magic to send information to database
          – Frendom
          Nov 19 '18 at 17:43












          Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
          – Caleb Lawrence
          Nov 19 '18 at 17:46






          Awesome glad you got it working. If you setup a route in you're flask app that will insert information into the database it should be really easy. This link has information about doing an AJAX Post: stackoverflow.com/questions/1960240/jquery-ajax-submit-form
          – Caleb Lawrence
          Nov 19 '18 at 17:46














          Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
          – Caleb Lawrence
          Nov 19 '18 at 17:47




          Also to implement the path in Flask check this out: stackoverflow.com/questions/11556958/… From there you would just have to use some sort of SQL library to insert it into the database.
          – Caleb Lawrence
          Nov 19 '18 at 17:47












          Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
          – Frendom
          Nov 19 '18 at 17:51




          Yeah, my app is in good status atm, so I have loging and adding some stuff to databse. Problem is that now I want to add opinion about books, so I need the book's id from nowhere and I dont want to refresh my site after submit opinion
          – Frendom
          Nov 19 '18 at 17:51












          Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
          – Caleb Lawrence
          Nov 19 '18 at 17:55




          Not sure what you mean by "need the book's id from nowhere". The opinion form is on a page where the book id is right? So you can have the id somewhere in your POST most likely? Also you shouldn't need to refresh the page if you're using AJAX. You can do a POST on the opinion form and then close the Modal without refreshing.
          – Caleb Lawrence
          Nov 19 '18 at 17:55


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378260%2fdisplaying-popup-with-flask-and-jquery%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith