0

Hi everyone. I want to make when i press a button to showup a dialog but page to not refresh or if refreshes to showup after that. i have this code but the dialog is going away after clicking the button

<form action="" method="post">
    <div class="col-xs-4 col-md-4">
    <a href="<?= $Link ?>" target="_blank" class="thumbnail">
        <img src="<?= $Image ?>" class="thumb-vote-image" alt="Item">
    </a>
    <h1><button name="<?= $ID ?>" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">VOTE</button></h1>
    <h3><?= $Name ?></h3>
    </div>
</form>

<?php
    if(isset($_POST[$ID])) {
        $vote = $ID;
?>
<!-- Modal -->
<div class="modal fade" id="myModal" 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"></h4>
        </div>
        <div class="modal-body">
            <center>
                <p>Item 1</p>
                <p>Item 2</p>
                <p>Item 3</p>
            </center>
        </div>
    </div>
</div>
</div>
<?php
}
3
Contributors
3
Replies
21
Views
5 Months
Discussion Span
Last Post by Stefan_1
1

Is it because you've placed the button inside a form and you have not prevented the default action (submit)?
Can't remember if buttons default to submit nor if modal js applies a preventDefault().

1

Oh god it worked :D i have forgoten to put type="button" in the <button> section :D
Thank you very much :)

Edited by Stefan_1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.