javascript form validation

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2008
Posts: 6
Reputation: penepepe is an unknown quantity at this point 
Solved Threads: 0
penepepe penepepe is offline Offline
Newbie Poster

javascript form validation

 
0
  #1
Aug 27th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: javascript form validation

 
0
  #2
Aug 27th, 2009
Hi,

try this for now:
  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>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 6
Reputation: penepepe is an unknown quantity at this point 
Solved Threads: 0
penepepe penepepe is offline Offline
Newbie Poster

Re: javascript form validation

 
0
  #3
Aug 27th, 2009
this works fine, thanks a lot!
but i still don't understand why mine doesn't work!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 313
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 50
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz

Re: javascript form validation

 
0
  #4
Aug 28th, 2009
In javascript 'If' cannot be capital, if u change the 'If' in your function to small letters 'if', it would work.
Life... Is a Moment
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 6
Reputation: penepepe is an unknown quantity at this point 
Solved Threads: 0
penepepe penepepe is offline Offline
Newbie Poster

Re: javascript form validation

 
0
  #5
Aug 28th, 2009
oh gosh, i didn't know, i'm a newbie! my script works now, i can't thank you enough! :d
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC