Hi there!

i've got an html form and i want to make sure some fields are not empty before it gets submitted. i've read many examples and i've written some code but i have no idea why it doesn't work (it's as if the javascript script didn't exist). i don't know if it matters but i use php and it's a self submitting form. here's my code:

<script language="javascript" type="text/javascript">
	function notEmpty(){
		If (document.email.eponimo.value.length==0)
			{
				alert("some message");
				document.email.eponimo.focus();	
				return false;
			}
		return true;	
	}
	
	
</script>

and a part of the form:

<form id="form" name="email" action="<?php echo $_SERVER['PHP_SELF'] ?>" onsubmit="return notEmpty()" enctype="multipart/form-data" method="post" >

<input type="text" name="eponimo"  size="35" /> 
<input id="btn" name="Submit" type="submit" value="ΑΠΟΣΤΟΛΗ"  />

thanks for your help

Hi,

try this for now:

<script type="text/javascript">
<!--
function notEmpty() {
   var _form = ( "form" in document ) ? form : document.getElementById("form");
   if ( _form.eponimo.value ) {
      return true;
   } alert( "field cannot be empty!" );
     _form.eponimo.focus();
      return false;
}

//-->
</script>

this works fine, thanks a lot!
but i still don't understand why mine doesn't work! :(

In javascript 'If' cannot be capital, if u change the 'If' in your function to small letters 'if', it would work.

oh gosh, i didn't know, i'm a newbie! my script works now, i can't thank you enough! :d

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.