Tuesday, September 21, 2004

Simple javascript alert

I was just asked by a colleague about a very simple javascript problem - he wanted a confirmation pop up but his code wasn't working properly. So here is the code

script
//confirmation - onclick event
function checkDelete(){
if(confirm("Are you really sure you want to format your hard drive?"))
{
return true;
}
else
{
return false;
}
}

/script

the button code
input name="btn_delete" type="button" id="btn_delete" value="Delete" onClick="return checkDelete();"


He had missed out the return in the onClick event.

No comments: