Steve Steve - 1 month ago 17
Javascript Question

Modal Dialog in Javascript

I am new to web development. I am currently using a .js modal dialog box that I found on the internet that is ok for now. What I want to know is, is there a nicer way to do this. Should I look at using jquery?

Thanks

Answer

You can try the popular Prototype JS library. Here's how you would do it in Prototype. The idea will be very similar in nearly all other JS libraries.

HTML:

<div style="display: none" id="message"></div>

CSS:

#message {
 position: absolute;
 left: 40%;
 top: 40%;
}

JS:

function modal(text) {
 $('message').update(text);
 $('message').appear();
}

modal('Any text you want to appear in the modal box');