Alert for button submission

Seems to me that the alert is still firing on page load, not when someone subscribes : (

Exactly! How can that be possible? Did I do everything you explained correctly?

Because your page still contains the following code:

$(document).ready(function () {
    setTimeout(function () {
       swal("Thank you!", "Your address has been successfully submitted!", "success");
    }, 1000);
});

Right now I just left

<script> swal("Thank you!", "Your address has been successfully submitted!", "success"); </script>

which should be the function to enable the alert when the button is clicked.

Result:
The alert does’t show up and the submission happen without none of the conditions set in your code is applied; in other words if you simply hit the button, an email containing nothing in it will arrive in my inbox. Again you may check it out by yourself.

Nope. This will display an alert when the page is loaded.

What should I do then?

Ok. Could you make a skeleton version of your page with most of the content and the other scripts stripped out?

All scripts in the page are jQuery’s. Do you want me to strip the page of all the jQuery contents?

Yeah, just remove all of the unnecessary stuff, like unrelated scripts. I’ll show you how to get the button sorted out, then you can add the rest back in making sure things don’t break.

Here I just commented out every script and call not concerning the button and your snippet.

Hi,

Just moving the scripts to the correct position (directly before closing <body> tag) seems to make things work.

<!DOCTYPE html>
<html>
<head>
  <base href="http://www.ilcontadinobio.it/tests/">
  <meta name="viewport" content="height=780, initial-scale=1">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="robots" content="index, follow" />
  <meta name="title" content="Azienda Agricola Biologica Il Contadino Bio" />
  <meta name="description" content="Azienda AgroBiologica Il Contadino Bio Giarre (Catania): ex limoneto in progressiva conversione ad agrumeto e frutteto con buona percentuale di specie subtropicali e tropicali. Più di 70 prodotti diversi certificati Bio. " />
  <meta name="keywords" content="Il Contadino Biologico, Agricoltura Biologica, biologico, bio, frutta tropicale, frutta subtropicale, Sicilia, frutta siciliana, vendita diretta, accorciamento della filiera, sano, buono, genuino, rispetto della natura" />
  <meta property="og:image" content="http://www.ilcontadinobio.it/images/A.png"/>
  <title>Azienda Agricola Biologica Il Contadino Bio</title>
  <link rel="shortcut icon" href="images/favicon.ico"/>
  <link rel="stylesheet" href="http://max.jotfor.ms/min/g=formCss?3.1.609" type="text/css" />
  <link rel="stylesheet" href="http://jotformeu.com/css/styles/industrial_dark.css?3.1.609" type="text/css" />
  <link rel="stylesheet" href="http://jotformeu.com/css/styles/buttons/form-submit-button-simple_green.css?3.1.609" type="text/css" />
  <link rel='stylesheet' href='css/camera.css' type='text/css' media='all' id='camera-css' />
  <link rel='stylesheet' href='css/csss.css' type='text/css'/>
  <link rel="stylesheet" href="css/menu6a.css" type="text/css"/>
<!--<script type='text/javascript' src="scripts/jquery-1.7.2.min.js"></script>
<script type='text/javascript' src='scripts/jquery.mobile.customized.min.js'></script>
<script type='text/javascript' src='scripts/jquery.easing.1.3.js'></script>
<script type='text/javascript' src='scripts/camera1.js'></script> -->

<link rel="stylesheet" type="text/css" href="dist/sweetalert.css">
<!--<script src="dist/sweetalert.min.js"></script>-->




<!-- image slider -->
<!--<script type="text/javascript">
jQuery(function(){
jQuery('#camera_wrap_1').camera({
thumbnails: true
});
jQuery('#camera_wrap_2').camera({
height: '400px',
loader: 'bar',
pagination: false,
thumbnails: true
});
});
</script>    -->

<!-- google analytics -->
<!--<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-27119547-1']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>-->



<script>

// swal("Thank you!", "Your address has been successfully submitted!", "success");
</script>

</head>
<body>

  <div class="outer">
    <table width="1024" border="0">
      <tr>
        <td>
          <object data="images/Azienda agricola Il Contadino Bio.swf" type="application/x-shockwave-flash" width="1024" height="197">
            <param name="movie" value="http://www.ilcontadinobio.swfit/images/Azienda%20agricola%20Il%20Contadino%20Bio"/>
            <param name="wmode" value="opaque"/>
            <object type="image/jpg" data="images/logo.jpg"></object>
          </object>
        </td>
      </tr>
    </table>
    <div id="sse2">
      <div id="sses2">
        <ul id="navList">
          <li class="buttonBox"><a href="index.html"><strong>Home</strong></a></li>
          <li class="buttonBox"><a href="azienda.html"><strong>Azienda</strong></a></li>
          <li class="buttonBox"><a href="prodotti.html"><strong>Prodotti</strong></a></li>
          <li class="buttonBox"><a href="filosofia.html"><strong>Agricoltura biologica</strong></a></li>
          <li class="buttonBox"><a href="guesthouse.html"><strong>Guesthouse</strong></a></li>
          <li class="buttonBox"><a href="eventi.html"><strong>Eventi</strong></a></li>
          <li class="buttonBox"><a href="gallery.html"><strong>Gallery</strong></a></li>
          <li class="buttonBox"><a href="distribuzione.html"><strong>Distribuzione</strong></a></li>
        </ul>
      </div>
    </div>
    <table border="0">
      <tr>
        <td width="1097">
          <div class="box">
            <div class="box-inner">
              <table width="1000" border="0" class="container" frame="void">
                <tr>
                  <td>
                    <br/>
                    <div class="fluid_container">
                      <div class="camera_wrap camera_azure_skin" id="camera_wrap_1">
                        <div data-thumb="images/slides1/thumbs/1.jpg" data-src="images/slides1/1.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/2.jpg" data-src="images/slides1/2.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/3.jpg" data-src="images/slides1/3.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/4.jpg" data-src="images/slides1/4.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/5.jpg" data-src="images/slides1/5.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/6.jpg" data-src="images/slides1/6.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/7.jpg" data-src="images/slides1/7.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                        <div data-thumb="images/slides1/thumbs/8.jpg" data-src="images/slides1/8.jpg">
                          <!--div class="camera_caption fadeFromBottom"></div-->
                        </div>
                      </div>
                    </div>
                  </td>
                </tr>
              </table>

              <table width="1024" border="1" cellspacing="16"  frame="void">

                <tr>
                  <td width="100"  valign="top"  class="container">
                    <h2 align="center" class="green"><strong>VIENI A TROVARCI</strong></h2>
                    <h2 align="justify">- In azienda: <strong>1^</strong> e <strong>3^</strong> domenica di ogni mese dalle ore <strong>10</strong> alle ore <strong>12</strong> previo appuntamento.</h2>
                    <p align="center">
                      <iframe width="237" height="150" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=via+ungaretti+giarre&amp;aq=&amp;sll=37.793312,14.820223&amp;sspn=0.009173,0.021136&amp;t=h&amp;g=via+ungaretti&amp;ie=UTF8&amp;hq=&amp;hnear=Via+Giuseppe+Ungaretti,+Giarre,+Catania,+Sicilia&amp;ll=37.711214,15.18894&amp;spn=9.165429,21.643066&amp;z=6&amp;output=embed"></iframe>
                      <br />
                      <small><a href="https://maps.google.it/maps?f=q&amp;source=embed&amp;hl=it&amp;geocode=&amp;q=via+ungaretti+giarre&amp;aq=&amp;sll=37.793312,14.820223&amp;sspn=0.009173,0.021136&amp;t=h&amp;g=via+ungaretti&amp;ie=UTF8&amp;hq=&amp;hnear=Via+Giuseppe+Ungaretti,+Giarre,+Catania,+Sicilia&amp;ll=37.711214,15.18894&amp;spn=9.165429,21.643066&amp;z=6" style="color:#0000FF;text-align:left">Visualizzazione ingrandita della mappa</a></small>
                    </p>
                    <h2 align="center">&nbsp;</h2>
                    <h2 align="center">Oppure</h2>
                    <h2 align="center">- Ogni seconda domenica del mese: <a href="http://www.aferabio.org" target="_blank"> <strong>A fera Bio Catania</strong></a> </h2>
                    <h2 align="center">&nbsp;</h2>
                    <h2 align="center">Online anche su:</h2>
                    <p align="center">&nbsp;</p>
                    <h2 align="center">Facebook</h2>
                    <h2 align="center">
                      <a href="https://www.facebook.com/afera.bjonica" target="_blank">
                        <img  width="160" src="images/aferabjonica.png" alt="Immagine" />
                      </a>
                    </h2>
                    <p align="center">&nbsp;</p>
                    <h2 align="center">Twitter</h2>
                    <p align="center">&nbsp;</p>
                    <p align="center">
                      <a href="https://twitter.com/BioEtnicaMente" target="_blank">
                        <img width="200" title="Il Contadino Bio" src="images/ilcontadinobio.png" alt="Immagine" />
                      </a>
                    </p>
                    <p align="center">&nbsp;</p>
                    <p align="center">
                      <a class="twitter-follow-button"
                      href="https://twitter.com/BioEtnicaMente"
                      data-show-count="false"
                      data-show-screen-name="false"
                      data-lang="en"
                      data-size="large"
                      data-align="middle">
                      Seguici @Twitter
                    </a>
                    <script type="text/javascript">
                      window.twttr = (function (d, s, id) {
                        var t, js, fjs = d.getElementsByTagName(s)[0];
                        if (d.getElementById(id)) return;
                        js = d.createElement(s); js.id = id;
                        js.src= "https://platform.twitter.com/widgets.js";
                        fjs.parentNode.insertBefore(js, fjs);
                        return window.twttr || (t = { _e: [], ready: function (f) { t._e.push(f) } });
                      }(document, "script", "twitter-wjs"));
                    </script>
                  </p>
                  <p>&nbsp;</p>
                  <h2 align="center" class="green"><strong>AZIENDE VICINE</strong></h2>
                  <h2 align="center"><a title="http://www.ilpigno.it/ilpigno.it/Home.html" href="http://www.ilpigno.it/ilpigno.it/Home.html" target="_blank">- Azienda agricola Il Pigno</a></h2>
                  <h2 align="center"><a title="http://www.barcavecchia.com" href="http://www.barcavecchia.com"  target="_blank">- Azienda agricola Barcavecchia</a></h2>
                  <h2 align="center"><a title="https://sites.google.com/site/bagolaro1/home" href="https://sites.google.com/site/bagolaro1/home"  target="_blank">- Azienda agricola Bagolaro</a></h2>
                  <p align="center">&nbsp;</p>
                  <h2 align="center" class="green"><strong>ASSOCIAZIONI</strong></h2>
                  <h2 align="center"><a title="http://www.aferabio.it" href="http://www.aferabio.it"  target="_blank">- &lsquo;A fera bio</a></h2>
                  <h2 align="center"><a title="http://www.associazioneserapide.org" href="http://www.associazioneserapide.org" target="_blank">- Associazione Serapide</a></h2>
                  <h2 align="center"><a title="http://www.mondomacondo.it" href="http://www.mondomacondo.it" target="_blank">- Associazione Macondo</a></h2>
                  <h2 align="center"><a title="http://www.gaslife.it" href="http://www.gaslife.it" target="_blank">- Gaslife</a></h2>
                  <p align="center">&nbsp;</p>
                </td>
                <td width="394" valign="top" class="container" id="up">
                  <table width="370" border="0">
                    <tr>
                      <td colspan="3">
                        <h2 align="center" class="green"><strong>ATTUALMENTE DISPONIBILE</strong></a></h2>
                        <h1 align="center">Frutta</h1>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="3">
                        <table width="200" border="0">
                          <tr>
                            <td>
                              <h2 align="center">Arance</h2>
                              <p><a href="../prodotti.html#Arancio"><img src="images/fruits/Arancio.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></p>
                            </td>
                            <td>
                              <h2 align="center">Arance amare</h2>
                              <p><a href="../prodotti.html#Arancioamaro"><img src="images/fruits/Arancioamaro.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></p>
                            </td>
                            <td>
                              <h2 align="center">Cedri</h2>
                              <p><a href="../prodotti.html#Cedro"><img src="images/fruits/Cedro.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></p>
                            </td>
                          </tr>
                          <tr>
                            <td>
                              <h2 align="center">Chinotti</h2>
                              <p><a href="../prodotti.html#Chinotto"><img src="images/fruits/Chinotto.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></p>
                            </td>
                            <td>
                              <h2 align="center">Limoni</h2>
                              <p><a href="../prodotti.html#Limone"><img src="images/fruits/limoni.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></p>
                            </td>
                            <td>
                              <h2 align="center">Pompelmi rosa</h2>
                              <p><a href="../prodotti.html#Pompelmorosa"><img src="images/fruits/Pompelmo rosa/Pompelmo rosa.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></p>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="3">
                        <table border="0">
                          <tr>
                            <td>
                              <a href="#up"><img src="images/arrow.gif" alt="Torna sopra" title="Torna sopra" width="50" height="50" align="middle" /></a>
                            </td>
                          </tr>
                        </table>
                        <h1 align="center">Erbe &amp; piante aromatiche</h1>
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <h2 align="center">Alloro</h2>
                        <div align="center">
                          <h2><a href="../prodotti.html#Alloro"><img class="border" src="images/fruits/Alloro.jpg" alt="Immagine" width="110" height="110" align="middle"/></a></h2>
                        </div>
                      </td>
                      <td>
                        <h2 align="center">Canna da zucch.</h2>
                        <div align="center">
                          <h2><a href="../prodotti.html#Canna da zucchero"><img class="border" src="images/fruits/Canna da zucchero.jpg" alt="Immagine" width="110" height="110" align="middle" /></a></h2>
                        </div>
                      </td>
                      <td>
                        <h2 align="center">Cedrina</h2>
                        <div align="center">
                          <h2><a href="../prodotti.html#Cedrina"><img class="border" src="images/fruits/Cedrina.jpg" alt="Immagine" width="110" height="110" align="middle" /></a></h2>
                        </div>
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <h2 align="center">Foglie di limone</h2>
                        <div align="center">
                          <h2><a href="../prodotti.html#Limonefoglie"><img src="images/fruits/limonefoglie.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></h2>
                        </div>
                      </td>
                      <td>
                        <h2 align="center">Nasturzio</h2>
                        <div align="center">
                          <h2><a href="../prodotti.html#Nasturzio"><img class="border" src="images/fruits/Nasturzio.jpg" alt="" width="110" height="110" align="middle" /></a></h2>
                        </div>
                      </td>
                      <td>
                        <h2 align="center">Rosmarino</h2>
                        <div align="center">
                          <h2><a href="../prodotti.html#Rosmarino"><img class="border" src="images/fruits/rosmarino.jpg" alt="" width="110" height="110" align="middle" /></a></h2>
                        </div>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="3">
                        <table border="0">
                          <tr>
                            <td>
                              <h2 align="center">Salvia</h2>
                              <div align="center">
                                <h2><a href="../prodotti.html#Salvia Officinalis"><img class="border" src="images/fruits/Salvia.jpg" alt="" width="110" height="110" align="middle" /></a></h2>
                              </div>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="3">
                        <table border="0">
                          <tr>
                            <td>
                              <a href="#up"><img src="images/arrow.gif" alt="Torna sopra" title="Torna sopra" width="50" height="50" align="middle" /></a>
                            </td>
                          </tr>
                        </table>
                        <h1 align="center">Fiori &amp; piante ornamentali</h1>
                      </td>
                    </tr>
                    <tr>
                      <td colspan="3">
                        <table border="0">
                          <tr>
                            <td>
                              <h2 align="center">Calle</h2>
                              <div align="center">
                                <h2><a href="../prodotti.html#Calle"><img src="images/fruits/Calle.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></h2>
                              </div>
                            </td>
                            <td>

                              <h2 align="center">Gladioli selvatici</h2>
                              <div align="center">
                                <h2><a href="../prodotti.html#Gladiolo"><img src="images/fruits/Gladiolo/Gladiolo.jpg" alt="Immagine" width="110" height="110" class="border" align="middle" /></a></h2>
                              </div>
                            </td>
                            <td>
                              <h2 align="center">Strelitzie</h2>
                              <div align="center">
                                <h2><a href="../prodotti.html#strelitzia"><img class="border" src="images/fruits/Strelitzia.jpg" alt="Immagine" width="110" height="110" align="middle" /></a></h2>
                              </div>
                            </td>
                          </tr>
                          <tr>
                            <td colspan="3">&nbsp;</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
                <td width="100" valign="top" class="container"><h2 align="center" class="green"><strong>LANGUAGE</strong></h2>
                  <p align="center"><a href="http://www.ilcontadinobio.it/index_en.html"  title="English"><img src="../images/United Kingdom.gif" width="74" height="58" alt="English language" /></a></p>
                  <p align="center">&nbsp;</p>
                  <div align="center"><img src="images/newsletter.png" alt="" width="140"/></div>
                  <h2 align="justify">Se vuoi rimanere aggiornato sulle novità, inviaci la tua e-mail:</h2>

                  <form method="post" action="mailcontadinobio.php">
                    <p align="center">
                      <input type="email" name="email" class="inputs" placeholder="esempio: mail@ilcontadinobio.it" id="email_address">
                      <table height="50" border="0">
                        <tr>
                          <td><div align="center">
                            <button type="submit" class="button animated" id="subscribe_button"><p>✓</p></button>
                          </div>
                        </td>
                      </tr>
                    </table>
                  </form>



                  <p>

                    ** Gli indirizzi e-mail pervenuti verranno manteniti confidenziali e strettamente riservati. </p>
                    <p align="justify">&nbsp;</p>
                    <h2 align="center" class="green"><strong>ARTICOLI</strong></h2>
                    <h2 align="center"><a href="http://www.siqillyah.eu/index.php?option=com_content%26view=article%26id=6:articolo-di-prova-4%26catid=1:articoli%26Itemid=9" target="_blank">&lsquo;A Fera Bjonica, a Giarre (CT)</a></h2>
                    <h2 align="center"><a href="http://www.forumetici.it/viewtopic.php?f=19&amp;t=14346&amp;sid=8641c52cf758ffa16c9445e544e7cb97">Fierabio anche a Giarre!!</a></h2>
                    <h2 align="center"><a href="http://comune-info.net/2012/06/e-tempo-di-fiere-e-mercati/"  target="_blank">È tempo di fiere e mercati </a></h2>
                    <h2 align="center"><a href="http://www.ricetteecooking.com/view.php/id_816/lingua_0/whoisit_1" target="_self" title="Frutta">Frutta esotica</a></h2>
                    <h2 align="center"><a href="http://www.verdeinsiemeweb.com/2012/12/hovenia-dulcis-lalbero-delluva-passa.html" target="_blank">Hovenia dulcis, l'albero dell'uva passa</a></h2>
                    <p align="center">&nbsp;</p>
                    <h2 align="center" class="green"><strong>CONSIGLIATI</strong></h2>
                    <h2 align="center">- <a href="mailto: anticofruttetodelmirio@virgilio.it">anticofruttetodelmirio@virgilio.it</a> (Frutta dell'Etna, Biancavilla)</h2>
                    <h2 align="center">- <a href="mailto: salvogiammello@tiscali.it">salvogiammello@tiscali.it</a> (Formaggio di capra amatoriale)</h2>
                    <h2 align="center">- <a href="mailto: zappalagiuseppe1969@gmail.com">zappalagiuseppe1969@gmail.com</a> (Frutta di montagna: mele, ciliegie, olive, noci)        </h2>
                    <p align="center">&nbsp;</p>
                    <h2 align="center" class="green"><strong>GAS</strong></h2>
                    <h2 align="center"><a title="http://www.gaslife.it/link-sferabio.html" href="http://www.gaslife.it/link-sferabio.html" target="_blank">- Sferabio</a></h2>
                    <h2 align="center"><a title="http://www.tapallara.it" href="http://www.tapallara.it" target="_blank">- Tapàllara</a></h2>
                  </td>
                </tr>
              </table>
            </div> <!-- .box-inner -->
            <div class="nsb_container" align="center">
              <p><a id="l1" target="_blank" rel="nofollow" href="http://www.facebook.com/sharer.php?u=http://www.ilcontadinobio.it/index.html">
                <img src="images/facebook.png" alt="Facebook" width="30" height="30" border="0" title="Facebook" />
              </a> &nbsp;
              <a id="l2" target="_blank" rel="nofollow" href="http://twitter.com/home?status=http://www.ilcontadinobio.it/index.html">
                <img src="images/twitter.png" alt="Twitter" width="30" height="30" border="0" title="Twitter" />
              </a>&nbsp;
              <a id="l4" target="_blank" rel="nofollow"   href="https://plus.google.com/u/0/share?url=http://www.ilcontadinobio.it/index.html">
                <img src="images/google.png" alt="Google Plus" width="30" height="30" border="0" title="Google Plus" />
              </a>&nbsp;</p>
            </div>
            <div style="clear:both;"></div>
          </div>
          <div class="black" align="center" >Copyright © 2012 - 2015 Il Contadino Bio - P.I. 00954760872 - <a class="black" href="mailto: mail@ilcontadinobio.it">mail@ilcontadinobio.it </a></div>
        </td>
      </tr>
    </table>
  </div> <!-- .outer -->
<!--<script src="dist/sweetalert.min.js"></script>
<script src="scripts/fitMenu.js" type="text/javascript"></script>
<script src="scripts/resizeListener.js" type="text/javascript"></script>
<script src="scripts/bubble6a.js" type="text/javascript"></script>
<script type="text/javascript">
var myElement = document.getElementById('navList'),
myResizeFn = function() {
fitMenu();
};
addResizeListener(myElement, myResizeFn);

window.onresize = fitMenu;
window.onload = fitMenu;
</script>-->

<script type='text/javascript' src="http://code.jquery.com/jquery-2.1.3.js"></script>


<!-- button -->
<script type="text/javascript">
  $("#subscribe_button").hover(
    function() {
      txt = $("#subscribe_button").children("p");
      txt.fadeOut(200, function() {
        txt.html("Sottoscrivi");
        txt.fadeIn();
      });
    }, function() {
      txt = $("#subscribe_button").children("p");
      txt.stop(true,false).fadeOut(200, function() {
        txt.html("✓");
        txt.fadeIn();
      });
    }
    );
  $("#subscribe_button").mousedown(function() {
    $(this).removeClass( "animated" );
  });
  $("#subscribe_button").mouseup(function() {
    $(this).addClass( "animated" );
  });

  $("#subscribe_button").on("click", function(e){
    e.preventDefault();
    var address = $("#email_address").val();
    if (!/\S+@\S+\.\S+/.test(address)){
      alert("Email address not valid!");
    } else {
      subscribeToNewsletter(address);
      $("#email_address").val("")
    }
  });
  function subscribeToNewsletter(address){
    $.ajax({
      url: 'mailcontadinobio.php',
      type: 'POST',
      data: {email: address}
    })
    .success(function(message) {
      alert(message);
    })
    .fail(function() {
      alert("There was a problem. Please try again later.");
    });
  }
</script>
</body>
</html>

Nice, but it is working with normal alerts not “sweetlert”. What would happen if I substituted the alert() function with the swal() one?

That one is intended for debugging use only. In some browsers it displays extra options to assist with debugging.There are a couple of images showing alerts with the extra options at http://javascriptexample.net/badjs12.php

I’d say, not only for debugging, but only for “quick and dirty” debugging. No reason a Pro can’t use console.log at the least and unit testing at best these days. It is no longer 20 - 30 years ago!

Especially since you used the word “intended,” this statement is very much wrong, and it continues to be wrong every time you repeat it.

alert() was not intended for debugging. It was intended to display messages to the user. Historically, before we had console logging, developers also used alert() for debugging messages. Emphasis on “historically” because I don’t think anyone uses it for that anymore.

In short, alert() was neither intended for, nor in modern practice is used for, debugging. And there’s absolutely no reason why we can’t use it for its original intended purpose: to display messages to the user.

OMG please no! As I said, for a “quick and dirty” development tool. sure (and even then console log usually far excells). But for a live site, never, if you please. If you must. modals are the way to go.

* my personal opinion

An alert() is a modal too. :wink: True story.

If you want a modal that’s prettier, as most people do, then an HTML+CSS modal is obviously the way to go. And even though an alert() may be a bit plain and boring to look at, “OMG please no!” seems like a severe overreaction.

1 Like

Did you try? : )

yes it looks plain and boring but if I turned the dialogs back on in my browser then I can click on the checkbox to turn off JavaScript on every web page that displays an alert.

Note that this alert was produced by a browser still listed as the latest version.

Ever since Netscape 4 died there have been a huge number of alternate ways of communicating with your visitors either modal or not that do not involve using the built in dialogs which were then repurposed for debugging prior to the proper debugging tools being added into the browser. It is only since they ceased to be needed for debugging that browsers started removing the extra options again.

Of course you can always turn the built in dialogs off so as not to be annoyed by debugging dialogs in case someone has accidentally left them in the page when the page went live.(which I have actually done with all the browsers I use.

I feel so out of my league :smile:

Yes, and it works but it clashes with the image slider which now is not working. If for instance I move your code back on top in the head, the opposite happen, namely image slider working and button alerts not.

This made me think about the setTimeout() function; I wanted to try and give some time to the one of the two, maybe it will solve the problem? I do not know either the correct way or where to place the function…