overriding onbeforeunlod for first step in form wizard

overriding onbeforeunlod for first step in form wizard

This pertains to a form wizard with 5 steps, I don't want the user to hit back and lose form data in any step 2-4. I have added a flag for the submit function and need to add this one for the first step. If they get there by accident and try and leave I dont want the cofirm dialog popping up.

<script type="text/javascript">
    $
(document).ready(function(){
     
var action_is_post = false;
    $
("form").submit(function () {
    action_is_post
= true;
 
});


//this is the trouble spot. on the first step the "navigation" of the form has a class
of current
(on step one = current)
$
(this).ready(function () {
if ($("#stepDesc0").is(".current")) {
action_is_post
= true;    
}
);  

window

.onbeforeunload = confirmExit;
function confirmExit()
{
if (!action_is_post)
return 'Using the browsers back, refresh or close button will cause you to lose all
form data
. Please use the Next and Back buttons on the form.';
}
});
</script>