Preventing A Form To Submit If A Field Is Empty

With this code, it alerts the user when the form is empty, but still submits it when the user clicks [OK]

<script type="text/javascript" language="JavaScript">
function nameempty()
        if ( == '' )
                alert('No name was entered!')
                return false;

<form action="submit.php" method="post" name="formname" onsubmit="return nameempty();">
<input type="text" name="name" class="textfield">
<input type="submit" value="Submit" name="submit">