You might look at jqueryui. That projects provides you with modal dialogs that should do what you want.

http://jqueryui.com/demos/dialog/

From the jqueryui site:

A call to $(foo).dialog() will initialize a dialog instance and will auto-open the dialog by default. If you want to reuse a dialog, the easiest way is to disable the "auto-open" option with: $(foo).dialog({ autoOpen: false }) and open it with $(foo).dialog('open'). To close it, use $(foo).dialog('close')

Answer from Jos Dirksen on Stack Overflow
๐ŸŒ
Rafaelfndev
rafaelfndev.github.io โ€บ jquery-msgpopup
jQuery Msg Popup - Simple and elegant popup messages :)
Script <script src="/dist/jquery-msgpopup.js"></script> You can check some examples here. $().msgpopup({ text: 'Test message', }); $().msgpopup({ text: 'Simple like that!', success: true, // false time: 5000, // or false x: true, // or false }); $().msgpopup({ text: 'Simple like that!', type: 'info', // or success, error, alert and normal time: 5000, // or false x: true, // or false }); Sorry, I need more time to documentation all D:
Discussions

Popup to Display Error Messages
๐ŸŒ forum.jquery.com
How to display error message in popup jquery - Stack Overflow
How to display error message in popup and if success message comes hide all the form fields and show success message. Presently i am doing like this: Placing a success message above the form and c... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 24, 2017
jQuery override default validation error message display (Css) Popup/Tooltip like - Stack Overflow
I'm trying to over ride the default error message label with a div instead of a label. I have looked at this post as well and get how to do it but my limitations with CSS are haunting me. How can I More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to display the jquery validation error message in popup?
How display the postcode error message only in alert or popup. Please any one help. ... The jQuery Validation Engine is not the same plugin. Please be aware when assigning tags. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Jquery
forum.jquery.com โ€บ topic โ€บ popup-to-display-error-messages
Jquery
August 21, 2010 - We cannot provide a description for this page right now
Top answer
1 of 7
186

You can use the errorPlacement option to override the error message display with little css. Because css on its own will not be enough to produce the effect you need.

$(document).ready(function(){
    $("#myForm").validate({
        rules: {
            "elem.1": {
                required: true,
                digits: true
            },
            "elem.2": {
                required: true
            }
        },
        errorElement: "div",
        wrapper: "div",  // a wrapper around the error message
        errorPlacement: function(error, element) {
            offset = element.offset();
            error.insertBefore(element)
            error.addClass('message');  // add a class to the wrapper
            error.css('position', 'absolute');
            error.css('left', offset.left + element.outerWidth());
            error.css('top', offset.top);
        }

    });
});

You can play with the left and top css attributes to show the error message on top, left, right or bottom of the element. For example to show the error on the top:

    errorPlacement: function(error, element) {
        element.before(error);
        offset = element.offset();
        error.css('left', offset.left);
        error.css('top', offset.top - element.outerHeight());
    }

And so on. You can refer to jQuery documentation about css for more options.

Here is the css I used. The result looks exactly like the one you want. With as little CSS as possible:

div.message{
    background: transparent url(msg_arrow.gif) no-repeat scroll left center;
    padding-left: 7px;
}

div.error{
    background-color:#F3E6E6;
    border-color: #924949;
    border-style: solid solid solid none;
    border-width: 2px;
    padding: 5px;
}

And here is the background image you need:


(source: scriptiny.com)

If you want the error message to be displayed after a group of options or fields. Then group all those elements inside one container a 'div' or a 'fieldset'. Add a special class to all of them 'group' for example. And add the following to the begining of the errorPlacement function:

errorPlacement: function(error, element) {
    if (element.hasClass('group')){
        element = element.parent();
    }
    ...// continue as previously explained

If you only want to handle specific cases you can use attr instead:

if (element.attr('type') == 'radio'){
    element = element.parent();
}

That should be enough for the error message to be displayed next to the parent element.

You may need to change the width of the parent element to be less than 100%.


I've tried your code and it is working perfectly fine for me. Here is a preview:

I just made a very small adjustment to the message padding to make it fit in the line:

div.error {
    padding: 2px 5px;
}

You can change those numbers to increase/decrease the padding on top/bottom or left/right. You can also add a height and width to the error message. If you are still having issues, try to replace the span with a div

<div class="group">
<input type="radio" class="checkbox" value="P" id="radio_P" name="radio_group_name"/>
<label for="radio_P">P</label>
<input type="radio" class="checkbox" value="S" id="radio_S" name="radio_group_name"/>
<label for="radio_S">S</label>
</div>

And then give the container a width (this is very important)

div.group {
    width: 50px; /* or any other value */
}

About the blank page. As I said I tried your code and it is working for me. It might be something else in your code that is causing the issue.

2 of 7
3

I use jQuery BeautyTips to achieve the little bubble effect you are talking about. I don't use the Validation plugin so I can't really help much there, but it is very easy to style and show the BeautyTips. You should look into it. It's not as simple as just CSS rules, I'm afraid, as you need to use the canvas element and include an extra javascript file for IE to play nice with it.

Top answer
1 of 2
5

Use errorPlacement option

errorPlacement (default: Places the error label after the invalid element) Type: Function() Customize placement of created error labels. First argument: The created error label as a jQuery object. Second argument: The invalid element as a jQuery object.

    errorPlacement: function(error,element){ 
                        //error.insertAfter(element); 
                        //use error.html() as content in your popup div or simply
                        alert(error.html());             
                     }
2 of 2
0

You can do this with errorPlacement

  1. Define a front-end with a hidden span option that will be used to populate dynamic errors.
  2. Set jquery.validate up to validate on a ruleset with custom messages
  3. Utilize errorPlacement to grab a handle on any error recognized by the validator.
  4. Upon error recognized, utilize jquery's .css function to assign visibility css to the span element.
  5. Upon success recognized, utilize jquery's .css function to assign invisibility css to the span element.

I've also noticed that the errorPlacement handler seems to respond to any change in the input box, but only display the popup when there is an actual error. It's probably some smart thing internally looking for an existing error, though I'm not sure.

$(document).ready(function() {
 $(".edit_order").validate({
      rules: {
        "order[purchase_order_number]": {
            // Disallow \ and / characters
            pattern: /^[^\\/]*$/,
            maxlength: 5,
        }
      },
      messages: {
        "order[purchase_order_number]": {
            pattern: "You cannot use \\ or / inside of your PO #",
            maxlength: "You cannot have a PO # larger than 5 characters"
        }
      },
      errorPlacement: function (error, element) {
      console.log("error?")
          // Grab the error from html generated by jquery.validate
          let content = error[0].textContent
console.log(error[0])
          // Populate the error tooltip with retrieved content
          $("#po-custom-popup").text(content)

          // Enable the error tooltip
          $(".error-popup-po-text").css({
              'visibility': 'visible',
              'opacity': 1
            })
      },
      success: function (label, element) {
          // Hide the tooltip or reset its visibility
          $(".error-popup-po-text").css({
              'visibility': 'hidden',
              'opacity': 0
          });
      },
    });
})
.error-popup-po .error-popup-po-text {
    width : 147px;
    visibility: hidden;
    background-color: #FFF;
    border-radius:4px;
    border: 1px solid #4e4e4e;
    position: absolute;
    z-index: 1;
    padding: 5px;
    margin-top : 5px;
    opacity: 0;
    transition: opacity 0.5s;
    color: #c40000;
    text-align: center;
}

.error-popup-po .error-popup-po-text::after {
    position: absolute;
    top: 5%;
    right: 100%;
    margin-top: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent #aeaeae transparent transparent;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.validate.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/additional-methods.js"></script>

<form class="edit_order">
<div class="error-popup-po">
  <div class="field_with_errors">
    <input type="text" name="order[purchase_order_number]">
  </div>
  
  <span id="po-custom-popup" class="error-popup-po-text" style="visibility: hidden; opacity: 0;"></span>
</div>
</form>

Find elsewhere
๐ŸŒ
jQuery
api.jquery.com โ€บ jQuery.error
jQuery.error() | jQuery API Documentation
The message to send out. This method exists primarily for plugin developers who wish to override it and provide a better display (or more information) for the error messages.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_popup.asp
JavaScript Popup Boxes
If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
๐ŸŒ
ByteScout
bytescout.com โ€บ blog โ€บ popup-message-using-jquery.html
How to Add Popup Message Window using JQuery โ€“ ByteScout
This is one of the simplest JQuery codes you can use to display a popup box in the window. What we have done here is to use APIs .show () and .close () to actually display and exit the dialog box. We have made the dialogue tag as a variable and made it appear and disappear from the window using ...
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ function-to-show-error-message-using-jquery
Function To Show Error Message Using jQuery
November 2, 2022 - validateFormValues = () => { let firstName = $("#firstName").val(); let lastName = $("#lastName").val(); let countryName = $("#countryName").val(); let subject = $("#Message").val(); let firstNameValueValid = 0; let lastNameValueValid = 0; let countryNameValueValid = 0; let subjectValueValid = 0; if (firstName != null && firstName != "") { firstNameValueValid = 1; $("#firstNamewrongValue").remove(); } else { firstNameValueValid = 0; dispalyErrorMessage("#firstNamewrongValue", "#firstName", "First Name Required."); } if (lastName != null && lastName != "") { lastNameValueValid = 1; $("#lastName
๐ŸŒ
Phpzag
phpzag.com โ€บ here-we-will-show-popup-message-for-few-seconds-using-jquery
Show Popup Message Few Seconds Using jQuery โ€“ PHPZAG.COM
April 2, 2024 - Steps3: JavaScript To Show and Hide Popup Here we have handled functionality to display popup with message and hide after three seconds using jQuery. function checkUser(usercheck){ var username = $('#username').val(); var password = $('#password').val(); if (!username) { $('#usercheck').show(); $('#usercheck').css('color', '#CC0000'); $('#usercheck').html('Please enter user name.'); $('#username').focus(); $('#username').addClass('error'); setTimeout("$('#usercheck').fadeOut(); ", 3000); } else if(!password) { $('#username').removeClass('error'); $('#passwordcheck').show(); $('#passwordcheck').css('color', '#CC0000'); $('#passwordcheck').html('Please enter password.'); $('#password').focus(); $('#password').addClass('error'); setTimeout("$('#passwordcheck').fadeOut(); ", 3000); } else { $('form#loginform').submit(); } }
๐ŸŒ
W3Schools
w3schools.com โ€บ jquery โ€บ event_error.asp
jQuery error() Method
The error() method was deprecated in jQuery version 1.8, and removed in version 3.0.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 30450327 โ€บ warning-message-popup
jquery - Warning Message Popup - Stack Overflow
0 jQuery warnings in Firefox Error Console ยท 0 How to display error message in popup jquery ยท 2 Jquery Pop-Up for Error Messages? 0 Popup message: Doesn't work with jquery 1.7 ยท 7 JQuery Pop up message ยท 0 updating a warning message using jQuery ยท 0 Issue in jquery validator popup message ยท
๐ŸŒ
ASPSnippets
aspsnippets.com โ€บ Articles โ€บ 784 โ€บ Display-error-messages-and-details-of-error-occurred-during-jQuery-AJAX-Call
Display error messages and details of error occurred during jQuery AJAX Call
July 10, 2014 - Error event handler in both the above case. This function accepts the following three parameters ... Inside this function, I have placed a TRY CATCH block and within the TRY block, the Exception received is parsed to a JSON object and then the details of the exception are displayed using jQuery Dialog Modal Popup.
๐ŸŒ
GitHub
gist.github.com โ€บ 1178948
JQuery plugin to add error messages to form elements from an object. ยท GitHub
July 12, 2018 - JQuery plugin to add error messages to form elements from an object. - jquery.errors.js