Chew Chew - 6 months ago 27
PHP Question

php echo modal doesn't work

i was trying to do is checking the user have enter any room before if they didnt leave the room they cant enter new room. but now i my modal wont show up. Anything i was doing wrong?

if($checkUser==0){

echo "<script>$('#myModal').modal('show');</script>

<div class='modal fade' id='myModal' role='dialog'>
<div class='modal-dialog modal-lg'>
<div class='modal-content'>
<div class='modal-body'>
<p>You didn't leave previous chatroom</p>
</div>
<div class='modal-footer'>
<a href='index.php'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Leave</button>
</a>
</div>
</div>
</div>
</div>";
}

Answer
if($checkUser==0){

    echo "<script>$(document).ready(function(){ $('#myModal').modal('show'); });</script>

        <div class='modal fade' id='myModal' role='dialog'>
            <div class='modal-dialog modal-lg'>
              <div class='modal-content'>
                <div class='modal-body'>
                  <p>You didn't leave previous chatroom</p>
                </div>
                    <div class='modal-footer'>
                        <a href='index.php'>
                            <button type='button' class='btn btn-default' data-dismiss='modal'>Leave</button>
                         </a>
                    </div>
                </div>
            </div>
        </div>";                                  
}

Add $('#myModal').modal('show'); into $(document).ready(); because at the time when js loaded #myModel does not loaded into DOM. Make sure to load Jquery before that