Javascript confirmation box not showing

Hi all i am having a strange problem with my javascript ajax script and what i am wanting to do is before the content gets submitted to the server to delete data from a database i want the user to confirm it if yes then it will be confirmed if not then it wont be.

this is my code

?>
        <script type="application/javascript">
		function term()
		{ 
		   //show the confirmation box 
		   var t=confirm('Are you sure you want to delete this account?');     
		} 
		</script>
		<form method="post" action="">
        <table>
        	<input type="hidden" name="usr" value="<?php echo $user; ?>"/>
            <tr> 
            	<th> <input type="submit" name="sus" value="Terminate User" onclick="term()" ></th>
            </tr>
        </table>
        </form>
		<?

What am i doing wrong??

My confirmation box doesnt show.

Thanks,William

You can stop a form submission by returning false from the onsubmit event handler


myFormElement.onsubmit = function(){
    return confirm("hi");
}

it is better to put onsubmit attribute for form element and true/false return from confirm will allow submission or block it. Something like this should work:


<form method="post" action="" onsubmit="return confirm('Are you sure you want to delete this account?');">
        <table>
            <input type="hidden" name="usr" value="<?php echo $user; ?>"/>
            <tr>
                <th>
                     <input type="submit" name="sus" value="Terminate User" />
                </th>
            </tr>
        </table>
        </form> 

you can make onsubmit call a separate function of course, as you had before if you need to put more code in there. But this gives you an idea.