Open the same modal with several buttons

Asked

Viewed 456 times

1

I am recovering the data from the mysql database, through a while, for each row of the database is generated a button, each button opens a modal window with details also coming from the database, but only the first button this opening the modal window!

html:

<?php  while ($row = $QUESTResult->fetch_array()) { ?>
<a id="test" class="active step"><?php echo $row['title']; ?></a>
<?php } ?>

<div class="ui modal test">
  <i class="close icon"></i>
  <div class="header">
    Profile Picture
  </div>
  <div class="image content">
    <div class="ui medium image">
      <img src="https://semantic-ui.com/images/avatar2/large/rachel.png">
    </div>
    <div class="description">
      <div class="ui header">We've auto-chosen a profile image for you.</div>
      <p>We've grabbed the following image from the <a href="https://www.gravatar.com" target="_blank">gravatar</a> image associated with your registered e-mail address.</p>
      <p>Is it okay to use this photo?</p>
    </div>
  </div>
  <div class="actions">
    <div class="ui black deny button">
      Nope
    </div>
    <div class="ui positive right labeled icon button">
      Yep, that's me
      <i class="checkmark icon"></i>
    </div>
  </div>
</div>

javascript:

<script type="text/javascript">
$(document).ready(function(){
        $("#test").click(function(){
            $(".test").modal('show');
        });
        $(".test").modal({
            closable: true
        });
});
</script>

NOTE: I am using Semantic-ui Framework

1 answer

1


The problem is that you are using the ID, which must be unique in several.

The correct is:

HTML:

<?php  while ($row = $QUESTResult->fetch_array()) { ?>
    <a id="test<?php echo $row["id"] ?>" class="active step"><?php echo $row['title']; ?></a>
<?php } ?>

It is necessary to generate different ID’s, eg: Test1, test2, teste3, test4, etc.

JS:

$("a[id^=\"test\"]").click(function(){
    $(".test").modal('show');
});
  • ah, yes thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.