using jquery dialog to submit a form on clicking yes button and cancel form submission on pressing no button

using jquery dialog to submit a form on clicking yes button and cancel form submission on pressing no button

I have been creating a page in jsp and passing the data to servlet, I have used jquery dialog as it can have customized buttons, even the dialog is not being displayed and it is directly submitting the form. I dont know how to display the dialog and submit a form on clicking "Yes" in dialog. Please help me in solving this below given is my JSP Page

JSP Page
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sample JQuery POC</title>
<script src="JQuery/Sample.js" type="text/javascript"></script>
<style>
    .ui-widget-header,.ui-state-default, ui-button
    {
            background:#b9cd6d;
            border: 1px solid #b9cd6d;
            color: #FFFFFF;
            font-weight: bold;
    }
 </style>
</head>
<body>
<center>
<form action="Controller" id="form" method="post" onsubmit="return dialogBox();">
    <div><b>Virtual directory 1:</b><input type="text" name="mytext" id="virtualText"></div>
<input type="submit" value="Submit" id="submit"/>
</form>
</center>
</body>
</html>

Jquery script
function dialogBox()
{
var flag;
var dynamicDialog = $('<div id="conformBox">'+
       '<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;">'+
       '</span>Are you sure to delete the item?</div>');
dynamicDialog.dialog({
        title : "Are you sure?",
        closeOnEscape: true,
        modal : true,

        buttons: {
            "Yes": function() {
            $( this ).dialog( "close" );
            flag = true;
            },
            "No": function() {
            flag  = false;
              $( this ).dialog( "close" );
              
            }
          }
});
return flag;
}

Please help me in this and assist me.