You are viewing limited content. For full access, please sign in.

Question

Question

How to display a pop up warning from JavaScript?

asked on August 19, 2014

Hi everyone,

 

I've used the code provided by Eric on this question and modified to do what I need, which is compare 2 different date fields. 

 

However, the 'warning' part of the code doesn't seem to work and I've tested it within IE and Chrome. We'd need a pop up alert letting them know why the form is not submitted. 

 

This is the code I'm using:

$(document).ready(function () {
    var d1 = new Date();
    var d2 = new Date();
    $('.date2').change(function () {
        if ($('.date1 input').val() == $('.date2 input').val()) {
         if ($('.ageWarning').length == 0) {
                $('<p class="ageWarning">The Start and End date of the Tuition Assistance form should not the same. Please verify.</p>').insertAfter('.ageLimit');
                $('.Submit').attr('disabled', true);
            }
        }
        else {
            $('p.ageWarning').remove();
            $('.Submit').removeAttr('disabled');
        }
    });
});

 

0 0

Answer

SELECTED ANSWER
replied on August 19, 2014 Show version history

If you want a popup, use alert().

 

alert('This is a warning popup!');

As written, your code inserts a warning message after a field with the ageLimit CSS class. If that CSS class is not present on the form, the warning message won't appear.

1 0
replied on August 19, 2014

That makes so much more sense now... and the alert worked! Thank you Eric!

0 0
replied on August 19, 2014

You're welcome!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.