I need to verify whether a text box is populated with a name. If it is empty, an alert message should be shown upon clicking the submit button, and the page should not proceed with submitting the blank value. If there is a value in the text box, then that value should be submitted.
Below is the code I am currently using. When I leave the text box empty and click on the submit button, the alert pops up as expected. However, the form still submits the empty value after dismissing the alert.
<html>
<head>
<script type="text/javascript">
function check()
{
if (!frm1.FileName.value)
{
alert ("Please Enter a File Name");
return (false);
}
return (true);
}
</script>
</head>
<body>
<form name="frm1" id="frm1" action="/cgi-bin/page.pl" method="POST">
<input type="text" name="FileName" id="FileName">
<input type="submit" value="send" name="btn_move" id="btn_move" onclick="check()">
</form>
</body>
</html>
What could be causing this issue in the code?