ok, if you are a web programmer, at one time or another, you are going to find this peace of code pretty uselful. it will save you server and bandwidth since javascript is not server side, but rather client side scripting.

today i was writing an HTML form, and i wanted to make sure that the user did not leave the name field blank. but instead, i wanted to force them into providing a field, so if the name field is empty, i want to prompt them with an alert (pop-up) window, telling them that they must provide a name. so this is how i did it..

DEMO: TRY IT (leave the name field blank and submit)

Name:




so how did it do it? well, if you want to know how, here is the code

<script type="text/javascript">
<!--
function validate_form ( ){
	UserName = true;
	if ( document.UserForm.UserName.value == "" ){
		alert ( "Name Blank: Please Enter Your Name" );
		return false;
		
	}
	alert('Hello '+document.UserForm.UserName.value == "");
	return true;
}
//-->
</script>
<form name="UserForm" method="post" action="" >
	Name: <br><input type="text" name="UserName"><br><br>
	<input type="button" name="JavascriptSubmit" onclick="return validate_form( );" value="Submit">
</form>