0

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

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by penepepe
0

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>
0

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

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.