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:
Answer from Jos Dirksen on Stack OverflowA 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')
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')
working demo click here
This might help rest I can see that @jos has given a API link: http://jqueryui.com/demos/dialog/
code for dialog
function showDialog() {
$("#dialog-modal").dialog({
resizable: true,
height: 140,
modal: true,
position: 'center',
buttons: {
'Yes': function () {
$(this).dialog("close");
return true;
},
'No': function () {
$(this).dialog("close");
return false;
}
}
});
};
$('input').click(function(){
showDialog();
});
โ
Popup to Display Error Messages
How to display error message in popup jquery - Stack Overflow
jQuery override default validation error message display (Css) Popup/Tooltip like - Stack Overflow
How to display the jquery validation error message in popup?
Videos
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.
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.
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());
}
You can do this with errorPlacement
- Define a front-end with a hidden span option that will be used to populate dynamic errors.
- Set jquery.validate up to validate on a ruleset with custom messages
- Utilize
errorPlacementto grab a handle on any error recognized by the validator. - Upon error recognized, utilize jquery's
.cssfunction to assign visibility css to the span element. - Upon success recognized, utilize jquery's
.cssfunction 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>
Yes, that is the correct way.
See the reference here:
http://www.javascriptkit.com/javatutors/error2.shtml
And explanation of how to see more details of the error here:
http://www.javascriptkit.com/javatutors/error3.shtml
Their example:
window.onerror = function(msg, url, linenumber) {
alert('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+linenumber);
return true;
}
If you wish to display a LIST of errors in a single pop-up, it's trickier.
Since the errors occue 1 by 1, you need to do the following:
- have
window.onerrorhandler store error details in some array Check that array periodically - either via a timer, or on every N'th call of
window.onerrorhandler, or both.When the check happens, process entire array, display contents as desired, and empty out an array
Just in case someone would like to use it with jQuery:
$(window).on("error", function(evt) {
console.log("jQuery error event:", evt);
var e = evt.originalEvent; // get the javascript event
console.log("original event:", e);
if (e.message) {
alert("Error:\n\t" + e.message + "\nLine:\n\t" + e.lineno + "\nFile:\n\t" + e.filename);
} else {
alert("Error:\n\t" + e.type + "\nElement:\n\t" + (e.srcElement || e.target));
}
});
You can add the ui-state-error class that comes in your theme, like this:
$("#div-dialog-warning").dialog({
title: t,
resizable: false,
height: 160,
modal: true,
buttons: {
"Ok" : function () {
$(this).dialog("close");
}
}
}).parent().addClass("ui-state-error");
Since the dialog gets wrapped we're using .parent() to get the container including the titlebar. Your theme looks like flick so here's a demo showing that theme in action.
I know this is old but, actually, it would be more suitable to use the built-in "dialogClass" option, like so:
$("#div-dialog-warning").dialog( {
buttons: {
"Ok" : function () {
$(this).dialog("close");
}
},
dialogClass: "error",
height: 160,
modal: true,
resizable: false,
title: t
} );
