Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript XHTML
I have created a web page that contains 2 text boxes that allow to enter two dates and javascript is used to validate the two text boxes are that empty. The out put is not coming as it wishes!
 
If the two text boxes are empty the javascript alert want work properly.
 
I post the source code at the below!
 
 
  <pre>!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function Validate()
{ var CheckInDate = document.getElementById(CheckIn).value;
  var CheckOutDate = document.getElementbyId(CheckOut).value;
  if var CheckInDate = "" || var CheckOutDate = "" {
    alert ("One or more fields empty"); } }
    </script>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="">
    <label>CheckIn Date <input type="text" name="CheckIn" id="CheckIn" /> </label>
    <p>
    <label>CheckOut Date <input type="text" name="CheckOut" id="CheckOut" />
    </label> </p> <p> <label>
    <input type="submit" name="Submit" id="Submit" value="Submit" onclick="Validate()" />
    </label>
    </p>
    </form>
    </body>
    </html>
Posted 29-Dec-11 21:45pm
Edited 29-Dec-11 21:46pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Your script is wrong, try this
function Validate()
{ var CheckInDate = document.getElementById('CheckIn').value;
  var CheckOutDate = document.getElementbyId('CheckOut').value;
  if(CheckInDate == "" || CheckOutDate == "") 
  {
    alert("One or more fields empty"); 
  } 
}
  Permalink  
v2
Comments
koolprasad2003 at 30-Dec-11 3:01am
   
Hey Raja, this is javascript. have you assign blank value "" to CheckInDate.
Please change assignment operator to comparison operator.
thatraja at 30-Dec-11 3:06am
   
Oops my bad, Sometimes it happens because worked in C#, VB, Classic ASP, js, etc., things sometimes confusing.
Anyway thanks.
koolprasad2003 at 30-Dec-11 3:50am
   
Same thing with me too. i also work with C#, VB many times.
Chiranthaka Sampath at 30-Dec-11 4:03am
   
The posted coding is not working!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

check following Javascript function
function Validate()
{ 
  var CheckInDate = document.getElementById('CheckIn').value;
  var CheckOutDate = document.getElementbyId('CheckOut').value;
  if(CheckInDate == "" || CheckOutDate == "")
  {
    alert("One or more fields empty");
    return false;
  }
}
  Permalink  
v2
Comments
Chiranthaka Sampath at 30-Dec-11 4:04am
   
Same result not working!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

modify this in your js function :
function Validate()
{ var CheckInDate = document.getElementById(CheckIn).value;
  var CheckOutDate = document.getElementbyId(CheckOut).value;
  if var CheckInDate = "" || var CheckOutDate = "" {
    alert ("One or more fields empty");
 
return false;}
 
return true;}
and in input tag in design :
<input type="submit" name="Submit" id="Submit" value="Submit" onclick="return Validate()" />
 
Hope this will help you.
Don't forget to mark as answer if it helps. Smile | :)
  Permalink  
Comments
Chiranthaka Sampath at 30-Dec-11 4:04am
   
Same result not working!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use below function
 
function Validate()
{ var CheckInDate = document.getElementById(CheckIn).value;
  var CheckOutDate = document.getElementbyId(CheckOut).value;
  if (CheckInDate = "" || CheckOutDate = "") {
    alert ("One or more fields empty"); return false; }return true; }
 

and change in button
 
<input type="submit" name="Submit" id="Submit" value="Submit" onclick="return Validate()" />
  Permalink  
Comments
Chiranthaka Sampath at 30-Dec-11 4:02am
   
I have use the above coding but gave the same result!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi, 
 
Change This also
 
<label>CheckIn Date</label> <input type="text" name="CheckIn" id="CheckIn" /> 
    <p>
    <label>CheckOut Date</label> <input type="text" name="CheckOut" id="CheckOut" />
     </p> <p> 
    <input type="submit" name="Submit" id="Submit" value="Submit" onclick="Validate()" />
 
Now Try.</p>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 30 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100