replace javascript alerts with modal

Prakash Bholah picture Prakash Bholah · Sep 11, 2013 · Viewed 14.1k times · Source

how to replace javascript alerts with a modal box?

The javascript alerts are triggered through an echo depending on some database results

if response is a
{
     <script type="text/javascript">alert("response is a.");</script>
}
else
{
    <script type="text/javascript">alert("response is not a.");</script>
}

I am using bootstrap, if we can replace the alerts with bootstrap modal its perfect

Answer

Kippie picture Kippie · Sep 11, 2013

Took the liberty of creating a jsbin example for you, based on the code you can find in the following question: JavaScript: Overriding alert()

http://jsbin.com/UzUDOno/1/edit

Do note that overriding alert may not be a great idea, especially because you'll be missing out on the blocking properties of regular javascript alerts. As you can see in my example, if you use 2 alerts in quick succession, the last one will override the one(s) before that.