Use div class in js validation

0

I have a login validation in js that generates an alert:

<script type="text/javascript">
var mensagem = "<?php echo (isset( $_SESSION['erroLogin'])?  $_SESSION['erroLogin'] : "false");?>";
    <?php unset($_SESSION['erroLogin']);?>
    if (mensagem != "false") {
        alert(mensagem);
    }
</script>

But I would like to use a custom alert that I have as an example on a button

<button class="md-btn" data-message="mensagem de alerta" data-pos="bottom-right">alerta</button>

Thank you in advance.

    
asked by anonymous 16.03.2016 / 20:31

1 answer

1

HTML:

<button class="md-btn validate" data-message="mensagem de alerta" data-pos="bottom-right">alerta</button>

JavaScript:

var mensagem = "<?php echo (isset( $_SESSION['erroLogin'])? $_SESSION['erroLogin'] : "false ");?>"; <?php unset($_SESSION['erroLogin']);?>

$('.validate').click(function() {
  var message = $(this).data('message');
  if (!mensagem) {
    alert(message)
  }
});

I'm not sure if this is what you wanted but here it goes.

The var message = $(this).data('message'); will get everything you put inside the data-message and show how to alert if there is any

    
16.03.2016 / 20:38