Is that code right ? I don't know if that function is true also or what and Is it a must to put that function code in the script section
<script>
function2(un)
{
if (typeof un == "undefined")
alert("enter text");
}
</script>
<form>
Username:
<input type="text" name="username"/>
<br/>
<input type="submit" value="Submit"onclick="function2(username)"/>
</form>