Before my development, I've already used native javascript alert for client side validation message. Some people might complaint why I used native javascript alert instead of jQuery dialogbox, it's because of I don't want to include so many script tags and CSS tags for jQuery mobile.

Today, I've got an idea to replace native javascript alert with cfmessagebox. This function will support to display cfmessagebox instead of javascript alert whenever we have put javascript alert in our coding.

view plain print about
1function DisplayMessageAlert (obj, messageText) {
2    /*
3        we need to use following coding for creating cfmessagebox object.
4    */

5    var RandCount = Math.random();
6    ColdFusion.MessageBox.create(obj + RandCount, 'Alert', 'Title', messageText);
7    ColdFusion.MessageBox.show(obj + RandCount);
8}

Here is how to replace native javascript alert with cfmessagebox.

view plain print about
1window.alert = function (message) {
2 DisplayMessageAlert('objError', message);
3};

Here is how to use after all.

view plain print about
1alert("This is javascript alert. But CFMessageBox will be displayed instead.")

Message:

All of above code will be embeded in script tag.