Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

please see what is wrong with my JS form validation

Posted on 2012-03-23
2
Medium Priority
?
254 Views
Last Modified: 2012-03-23
Hi,

My code below is ignoring the validation and sending to the server.
Can someone please see why this is happening?

<html>
<head><title>An event</title>

<script type="text/javascript">

function checkForm() {

if (document.getElementById("name1") == "" ||
      document.getElementById("name1") == null) {
      alert("Please enter your name");
      return (false);      
      }
      else {
      return (true);
}
}



</script>
</head>
 <body>

 <form onSubmit="return checkForm(this)" action="post.php" method="post">
 <label><b>Type your name here : </b></label>
 <input type="text" id="name1"/><br />
 <input type="Submit" /><input type="reset" value="Clear" />
 

 </form>
</center>
</body>
</html>
0
Comment
Question by:jecommera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
ingriT earned 2000 total points
ID: 37757337
document.getElementById("name1").value == "" ||
      document.getElementById("name1").value == null

see http://www.w3schools.com/js/js_form_validation.asp for more tips and tricks!
0
 

Author Closing Comment

by:jecommera
ID: 37757372
ah of course - thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question