How to display dynamic content from database on bootstrap modal by using button id on djangoHow to prevent buttons from submitting formsHow do you get centered content using Twitter Bootstrap?Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape?Open Django template in bootstrap ModalCannot display HTML stringHow can I style 2 ui-bootstrap modals differently?How to validate a form in a bootstrap modal window in wicket?How to insert modal dialog from python plugin[Django]?Generate modal pop up with dynamic data from button click on table rowDjango-Bootstrap : form modal close button doesn't work

Why not make one big CPU core?

Is fission/fusion to iron the most efficient way to convert mass to energy?

What is wind "CALM"?

How do credit card companies know what type of business I'm paying for?

Can Dive Down protect a creature against Pacifism?

What made the Ancient One do this in Endgame?

Does WiFi affect the quality of images downloaded from the internet?

Will users know a CardView is clickable

Why is gun control associated with the socially liberal Democratic party?

Difference between "drift" and "wander"

Sakkāya-Ditthi and Self-View

Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?

Can artificial satellite positions affect tides?

how can non-magical soldiers gain power from a magic ritual without making its participants weaker?

Can an escape pod land on Earth from orbit and not be immediately detected?

How many possible starting positions are uniquely solvable for a nonogram puzzle?

Should I worry about having my credit pulled multiple times while car shopping?

How do I say what something is made out of?

How can this shape perfectly cover a cube?

New Site Design!

Bullying by school - Submitted PhD thesis but not allowed to proceed to viva until change to new supervisor

Do items with curse of vanishing disappear from shulker boxes?

Jam with honey & without pectin has a saucy consistency always

Print the phrase "And she said, 'But that's his.'" using only the alphabet



How to display dynamic content from database on bootstrap modal by using button id on django


How to prevent buttons from submitting formsHow do you get centered content using Twitter Bootstrap?Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape?Open Django template in bootstrap ModalCannot display HTML stringHow can I style 2 ui-bootstrap modals differently?How to validate a form in a bootstrap modal window in wicket?How to insert modal dialog from python plugin[Django]?Generate modal pop up with dynamic data from button click on table rowDjango-Bootstrap : form modal close button doesn't work






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am loading bootstrap cards with brief university details using a for loop with context passed from my django view. Now, I want to display a modal with more details depending on which card's button I press. I would like this dynamic data to be displayed without reloading/refreshing the page.



this is my views.py



from django.shortcuts import get_object_or_404
from django.http import JsonResponse
from university.models import University


def dispUni(request):

# hoping to retrieve university.id from the clicked button
uniPK = request.GET.get('universityId')

uniDetails =
'university': get_object_or_404(University, id=uniPK)


return JsonResponse(uniDetails)


this is my urls.py



from django.urls import path

from . import views

urlpatterns = [
path('', views.dispUni, name='uniDetails')
]


This is my html page where I want to display this information



<div class="container-fluid d-flex justify-content-center">
<!-- display Universities -->
<div class="row mt-5">
% if universities %
% for university in universities %

<div class="card mx-4 uniCard" style="width: 20rem;">
<img src="university.photo_main.url" class="card-img-top" alt="university.title">
<div class="card-body">
<h5 class="card-title Dark-shades-text">university.title</h5>
<p class="card-text">
<i class="fas fa-map-marked-alt"></i>&nbsp;university.city, university.state <br>
<i class="fas fa-phone"></i>&nbsp;university.phone_number
</p>
<!-- Button trigger modal -->
<button type="button" value="university.id" id="btn-UniModaluniversity.id" class="btn main-color" data-toggle="modal" data-target="#UniDetails">
View Details
</button>
</div>
</div>

% endfor %
% endif %
</div>
</div>

<!-- Modal for University Details -->
<div class="modal fade" id="UniDetails" tabindex="-1" role="dialog" aria-labelledby="UniInformation" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="UniModalTitle"><!-- Expected title of university button pressed --></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Expected details of university button pressed -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Apply</button>
</div>
</div>
</div>
</div>









share|improve this question




























    1















    I am loading bootstrap cards with brief university details using a for loop with context passed from my django view. Now, I want to display a modal with more details depending on which card's button I press. I would like this dynamic data to be displayed without reloading/refreshing the page.



    this is my views.py



    from django.shortcuts import get_object_or_404
    from django.http import JsonResponse
    from university.models import University


    def dispUni(request):

    # hoping to retrieve university.id from the clicked button
    uniPK = request.GET.get('universityId')

    uniDetails =
    'university': get_object_or_404(University, id=uniPK)


    return JsonResponse(uniDetails)


    this is my urls.py



    from django.urls import path

    from . import views

    urlpatterns = [
    path('', views.dispUni, name='uniDetails')
    ]


    This is my html page where I want to display this information



    <div class="container-fluid d-flex justify-content-center">
    <!-- display Universities -->
    <div class="row mt-5">
    % if universities %
    % for university in universities %

    <div class="card mx-4 uniCard" style="width: 20rem;">
    <img src="university.photo_main.url" class="card-img-top" alt="university.title">
    <div class="card-body">
    <h5 class="card-title Dark-shades-text">university.title</h5>
    <p class="card-text">
    <i class="fas fa-map-marked-alt"></i>&nbsp;university.city, university.state <br>
    <i class="fas fa-phone"></i>&nbsp;university.phone_number
    </p>
    <!-- Button trigger modal -->
    <button type="button" value="university.id" id="btn-UniModaluniversity.id" class="btn main-color" data-toggle="modal" data-target="#UniDetails">
    View Details
    </button>
    </div>
    </div>

    % endfor %
    % endif %
    </div>
    </div>

    <!-- Modal for University Details -->
    <div class="modal fade" id="UniDetails" tabindex="-1" role="dialog" aria-labelledby="UniInformation" aria-hidden="true">
    <div class="modal-dialog modal-dialog-scrollable" role="document">
    <div class="modal-content">
    <div class="modal-header">
    <h5 class="modal-title" id="UniModalTitle"><!-- Expected title of university button pressed --></h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
    <span aria-hidden="true">&times;</span>
    </button>
    </div>
    <div class="modal-body">
    <!-- Expected details of university button pressed -->
    </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    <button type="button" class="btn btn-primary">Apply</button>
    </div>
    </div>
    </div>
    </div>









    share|improve this question
























      1












      1








      1








      I am loading bootstrap cards with brief university details using a for loop with context passed from my django view. Now, I want to display a modal with more details depending on which card's button I press. I would like this dynamic data to be displayed without reloading/refreshing the page.



      this is my views.py



      from django.shortcuts import get_object_or_404
      from django.http import JsonResponse
      from university.models import University


      def dispUni(request):

      # hoping to retrieve university.id from the clicked button
      uniPK = request.GET.get('universityId')

      uniDetails =
      'university': get_object_or_404(University, id=uniPK)


      return JsonResponse(uniDetails)


      this is my urls.py



      from django.urls import path

      from . import views

      urlpatterns = [
      path('', views.dispUni, name='uniDetails')
      ]


      This is my html page where I want to display this information



      <div class="container-fluid d-flex justify-content-center">
      <!-- display Universities -->
      <div class="row mt-5">
      % if universities %
      % for university in universities %

      <div class="card mx-4 uniCard" style="width: 20rem;">
      <img src="university.photo_main.url" class="card-img-top" alt="university.title">
      <div class="card-body">
      <h5 class="card-title Dark-shades-text">university.title</h5>
      <p class="card-text">
      <i class="fas fa-map-marked-alt"></i>&nbsp;university.city, university.state <br>
      <i class="fas fa-phone"></i>&nbsp;university.phone_number
      </p>
      <!-- Button trigger modal -->
      <button type="button" value="university.id" id="btn-UniModaluniversity.id" class="btn main-color" data-toggle="modal" data-target="#UniDetails">
      View Details
      </button>
      </div>
      </div>

      % endfor %
      % endif %
      </div>
      </div>

      <!-- Modal for University Details -->
      <div class="modal fade" id="UniDetails" tabindex="-1" role="dialog" aria-labelledby="UniInformation" aria-hidden="true">
      <div class="modal-dialog modal-dialog-scrollable" role="document">
      <div class="modal-content">
      <div class="modal-header">
      <h5 class="modal-title" id="UniModalTitle"><!-- Expected title of university button pressed --></h5>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      </div>
      <div class="modal-body">
      <!-- Expected details of university button pressed -->
      </div>
      <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      <button type="button" class="btn btn-primary">Apply</button>
      </div>
      </div>
      </div>
      </div>









      share|improve this question














      I am loading bootstrap cards with brief university details using a for loop with context passed from my django view. Now, I want to display a modal with more details depending on which card's button I press. I would like this dynamic data to be displayed without reloading/refreshing the page.



      this is my views.py



      from django.shortcuts import get_object_or_404
      from django.http import JsonResponse
      from university.models import University


      def dispUni(request):

      # hoping to retrieve university.id from the clicked button
      uniPK = request.GET.get('universityId')

      uniDetails =
      'university': get_object_or_404(University, id=uniPK)


      return JsonResponse(uniDetails)


      this is my urls.py



      from django.urls import path

      from . import views

      urlpatterns = [
      path('', views.dispUni, name='uniDetails')
      ]


      This is my html page where I want to display this information



      <div class="container-fluid d-flex justify-content-center">
      <!-- display Universities -->
      <div class="row mt-5">
      % if universities %
      % for university in universities %

      <div class="card mx-4 uniCard" style="width: 20rem;">
      <img src="university.photo_main.url" class="card-img-top" alt="university.title">
      <div class="card-body">
      <h5 class="card-title Dark-shades-text">university.title</h5>
      <p class="card-text">
      <i class="fas fa-map-marked-alt"></i>&nbsp;university.city, university.state <br>
      <i class="fas fa-phone"></i>&nbsp;university.phone_number
      </p>
      <!-- Button trigger modal -->
      <button type="button" value="university.id" id="btn-UniModaluniversity.id" class="btn main-color" data-toggle="modal" data-target="#UniDetails">
      View Details
      </button>
      </div>
      </div>

      % endfor %
      % endif %
      </div>
      </div>

      <!-- Modal for University Details -->
      <div class="modal fade" id="UniDetails" tabindex="-1" role="dialog" aria-labelledby="UniInformation" aria-hidden="true">
      <div class="modal-dialog modal-dialog-scrollable" role="document">
      <div class="modal-content">
      <div class="modal-header">
      <h5 class="modal-title" id="UniModalTitle"><!-- Expected title of university button pressed --></h5>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
      </button>
      </div>
      <div class="modal-body">
      <!-- Expected details of university button pressed -->
      </div>
      <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      <button type="button" class="btn btn-primary">Apply</button>
      </div>
      </div>
      </div>
      </div>






      python html ajax django bootstrap-modal






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 2:33









      Haamid AshrafHaamid Ashraf

      63




      63






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I believe this could easily be solved with Javascript. You could place an onclick attribute on the button that calls a function to update the model.



          The title can be updated with:






          document.getElementById("UniModalTitle").innerHTML = "University Title";





          Then for updating the details it's the same process but with a different id. You'll need to give the model body an id to make this work.






          share|improve this answer

























          • I need the title to come from the database, this wouldn't achieve what I need

            – Haamid Ashraf
            Mar 25 at 3:34











          • What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

            – Daniel van der Ploeg
            Mar 25 at 3:37











          • okay, thanks. I get it now.

            – Haamid Ashraf
            Mar 25 at 3:42











          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%2f55330573%2fhow-to-display-dynamic-content-from-database-on-bootstrap-modal-by-using-button%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














          I believe this could easily be solved with Javascript. You could place an onclick attribute on the button that calls a function to update the model.



          The title can be updated with:






          document.getElementById("UniModalTitle").innerHTML = "University Title";





          Then for updating the details it's the same process but with a different id. You'll need to give the model body an id to make this work.






          share|improve this answer

























          • I need the title to come from the database, this wouldn't achieve what I need

            – Haamid Ashraf
            Mar 25 at 3:34











          • What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

            – Daniel van der Ploeg
            Mar 25 at 3:37











          • okay, thanks. I get it now.

            – Haamid Ashraf
            Mar 25 at 3:42















          0














          I believe this could easily be solved with Javascript. You could place an onclick attribute on the button that calls a function to update the model.



          The title can be updated with:






          document.getElementById("UniModalTitle").innerHTML = "University Title";





          Then for updating the details it's the same process but with a different id. You'll need to give the model body an id to make this work.






          share|improve this answer

























          • I need the title to come from the database, this wouldn't achieve what I need

            – Haamid Ashraf
            Mar 25 at 3:34











          • What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

            – Daniel van der Ploeg
            Mar 25 at 3:37











          • okay, thanks. I get it now.

            – Haamid Ashraf
            Mar 25 at 3:42













          0












          0








          0







          I believe this could easily be solved with Javascript. You could place an onclick attribute on the button that calls a function to update the model.



          The title can be updated with:






          document.getElementById("UniModalTitle").innerHTML = "University Title";





          Then for updating the details it's the same process but with a different id. You'll need to give the model body an id to make this work.






          share|improve this answer















          I believe this could easily be solved with Javascript. You could place an onclick attribute on the button that calls a function to update the model.



          The title can be updated with:






          document.getElementById("UniModalTitle").innerHTML = "University Title";





          Then for updating the details it's the same process but with a different id. You'll need to give the model body an id to make this work.






          document.getElementById("UniModalTitle").innerHTML = "University Title";





          document.getElementById("UniModalTitle").innerHTML = "University Title";






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 25 at 3:37

























          answered Mar 25 at 3:23









          Daniel van der PloegDaniel van der Ploeg

          112




          112












          • I need the title to come from the database, this wouldn't achieve what I need

            – Haamid Ashraf
            Mar 25 at 3:34











          • What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

            – Daniel van der Ploeg
            Mar 25 at 3:37











          • okay, thanks. I get it now.

            – Haamid Ashraf
            Mar 25 at 3:42

















          • I need the title to come from the database, this wouldn't achieve what I need

            – Haamid Ashraf
            Mar 25 at 3:34











          • What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

            – Daniel van der Ploeg
            Mar 25 at 3:37











          • okay, thanks. I get it now.

            – Haamid Ashraf
            Mar 25 at 3:42
















          I need the title to come from the database, this wouldn't achieve what I need

          – Haamid Ashraf
          Mar 25 at 3:34





          I need the title to come from the database, this wouldn't achieve what I need

          – Haamid Ashraf
          Mar 25 at 3:34













          What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

          – Daniel van der Ploeg
          Mar 25 at 3:37





          What do you mean? Just replace University Title with a variable? onclick="document.getElementById('UniModalTitle').innerHTML = 'university.title'";

          – Daniel van der Ploeg
          Mar 25 at 3:37













          okay, thanks. I get it now.

          – Haamid Ashraf
          Mar 25 at 3:42





          okay, thanks. I get it now.

          – Haamid Ashraf
          Mar 25 at 3:42



















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330573%2fhow-to-display-dynamic-content-from-database-on-bootstrap-modal-by-using-button%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현