Friday, December 4, 2009

Putting a confirm dialog box on a HTML widget

In HTML forms there is typically a need to put some kind of confirmation when you are submitting a form such as "Are you sure?", "You are over the limit, is this okay?" etc.

This confirmation can be tied to any HTML widget not just a submit button.

The JavaScript code below shows how to do this:


$(document).ready(function() {
$('#confirm').click(function() {

var checked = $('#terms').attr('checked');
if(!checked)
{
return confirm('Are you sure?');
}
return true;
});
});


The above JS function is tied to onClick() event on the button with id="confirm" on an HTML form. The HTML form is unaware of this function, the button code is simply


< input type="checkbox" checked="" id="terms"/>
< input type="submit" value="Create New Zone" id="confirm">

Thursday, February 26, 2009

HTML goodies

to render ellipses (...) use "&hellip"