NGabioud
NGabioud

Reputation: 375

Popup Message using Javascript / jQuery

I based in How to generate a simple popup using jQuery to creat a Popup Message so you can complete some data to get a result.

The code in the answer to that question works good, but I need - at least- 2 different popup message and I can't get that working.

The popup message appears, but when I hit cancel it doesn't close - and it does when i hit the "open" button. Can you see what I'm doing wrong? I'm new to Javascript.

Also, I would like the popup to close if the user hits download (Descargar).

$(function() {
  $('#ticketsGenerados').on('click', function() {
    $('#ticketsGeneradosPop').slideFadeToggle();
    return false;
  });

  $('closeticketsGeneradosPop').on('click', function() {
    $('#ticketsGeneradosPop').slideFadeToggle();
    return false;
  });
});


$(function() {
  $('#ticketsCierreAdmin').on('click', function() {
    $('#ticketsCierreAdminPop').slideFadeToggle();
    return false;
  });

  $('closeticketsCierreAdminPop').on('click', function() {
    $('#ticketsCierreAdminPop').slideFadeToggle();
    return false;
  });
});


$.fn.slideFadeToggle = function(easing, callback) {
  return this.animate({
    opacity: 'toggle',
    height: 'toggle'
  }, 'fast', easing, callback);
};
/* Z-index of #mask must lower than #boxes .window */

.messagepop {
            background-color:#FFFFFF;
            border:1px solid #999999;
            cursor:default;
            display:none;
            margin-top: 15px;
            position:absolute;
            text-align:left;
            width:394px;
            z-index:50;
            padding: 25px 25px 20px;
        }

        .labelPop {
            display: block;
            margin-bottom: 3px;
            padding-left: 15px;
            text-indent: -15px;
        }

        .messagepop p, .messagepop.div {
            border-bottom: 1px solid #EFEFEF;
            margin: 8px 0;
            padding-bottom: 8px;
        }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="messagepop pop" id="ticketsGeneradosPop">
  <form method="post" id="new_message" action="bajadas/ticketsGenerados.php">
    <p>Fechas a considerar en el reporte:</p>
    <p><label class="labelPop" for="email">Fecha inicio</label><input type="date" name="fechaInicio" /></p>
    <p><label class="labelPop" for="body">Fecha fin</label><input type="date" name="fechaFin" /></p>
    <p><input type="submit" value="Descargar" /> o <a id="closeticketsGeneradosPop" href="#">Cancelar</a></p>
  </form>
</div>

<div class="messagepop pop" id="ticketsCierreAdminPop">
  <form method="post" id="new_message" action="bajadas/ticketsCierreAdministrativo.php">
    <p>Fechas a considerar en el reporte:</p>
    <p><label class="labelPop" for="email">Fecha inicio</label><input type="date" name="fechaInicio" /></p>
    <p><label class="labelPop" for="body">Fecha fin</label><input type="date" name="fechaFin" /></p>
    <p><input type="submit" value="Descargar" /> o <a id="closeticketsCierreAdminPop" href="#">Cancelar</a></p>
  </form>
</div>

<a href="bajadas/ticketsAbiertos.php" class="botonesBajadas">Tickets abiertos</a>
<a href="#" class="botonesBajadas" id="ticketsGenerados">Tickets generados</a>
<a href="#" class="botonesBajadas" id="ticketsCierreAdmin">Tickets cierre adminitrativo</a>

Upvotes: 0

Views: 392

Answers (1)

Gaspar Teixeira
Gaspar Teixeira

Reputation: 1267

Take a look on this code:

    $('closeticketsGeneradosPop').on('click', function() {
    $('#ticketsGeneradosPop').slideFadeToggle();
    return false;
  });

They need to be thus:

    $('#closeticketsGeneradosPop').on('click', function() {
    $('#ticketsGeneradosPop').slideFadeToggle();
    return false;
  });

Don't forget the # before to identify an element in jQuery.

Upvotes: 2

Related Questions