943,673 Members | Top Members by Rank

Ad:
Aug 27th, 2009
0

javascript form validation

Expand Post »
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="javascript" type="text/javascript">
  2. function notEmpty(){
  3. If (document.email.eponimo.value.length==0)
  4. {
  5. alert("some message");
  6. document.email.eponimo.focus();
  7. return false;
  8. }
  9. return true;
  10. }
  11.  
  12.  
  13. </script>

and a part of the form:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form id="form" name="email" action="<?php echo $_SERVER['PHP_SELF'] ?>" onsubmit="return notEmpty()" enctype="multipart/form-data" method="post" >
  2.  
  3. <input type="text" name="eponimo" size="35" />
  4. <input id="btn" name="Submit" type="submit" value="ΑΠΟΣΤΟΛΗ" />

thanks for your help
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
penepepe is offline Offline
6 posts
since May 2008
Aug 27th, 2009
0

Re: javascript form validation

Hi,

try this for now:
javascript Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. <!--
  3. function notEmpty() {
  4. var _form = ( "form" in document ) ? form : document.getElementById("form");
  5. if ( _form.eponimo.value ) {
  6. return true;
  7. } alert( "field cannot be empty!" );
  8. _form.eponimo.focus();
  9. return false;
  10. }
  11.  
  12. //-->
  13. </script>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 27th, 2009
0

Re: javascript form validation

this works fine, thanks a lot!
but i still don't understand why mine doesn't work!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
penepepe is offline Offline
6 posts
since May 2008
Aug 28th, 2009
0

Re: javascript form validation

In javascript 'If' cannot be capital, if u change the 'If' in your function to small letters 'if', it would work.
Reputation Points: 36
Solved Threads: 57
Posting Whiz
Thirusha is offline Offline
355 posts
since Mar 2008
Aug 28th, 2009
0

Re: javascript form validation

oh gosh, i didn't know, i'm a newbie! my script works now, i can't thank you enough! :d
Reputation Points: 10
Solved Threads: 0
Newbie Poster
penepepe is offline Offline
6 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript help
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: select/save selected records





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC