Use div class in js validation

Asked

Viewed 67 times

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>

Thanks in advance.

  • 1

    You want Alert to be called when you click the button?

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 goes.

The var message = $(this).data('message'); will take everything you put inside the data-message and show as Alert if there is any

Browser other questions tagged

You are not signed in. Login or sign up in order to post.