Jump to content

Validate empty text box in java script


tiota

Recommended Posts

I have a form that enforce users to fill in using java script. My java script checks that the form is filled in otherwise informing the users to fill in text box.

 

Suprisingly, some users manage to bypass this validation when they press Enter button on the keyboard. How can this happen ?

 

Your help is pretty much appreciated.

 

See my code below

 

<script language="javascript">

function Validate() {

 

 

reasons = document.LateForm.latereasons.value

empnum = document.LateForm.empnum.value

 

 

if (empnum == "")

{

Message = "Please enter your PF number" + "\n"

alert(Message)

return false

}

if (reasons == "")

{

Message = "Please state your reasons why do you come late" + "\n"

alert(Message)

return false

}

 

 

else

{

Message = ""

document.LateForm.submit()

return true

}

}

 

</script>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

  <title>Late Form</title>

  <LINK REL=StyleSheet HREF="timecardbasic.css" TYPE="text/css" MEDIA=screen>

</head>

<body>

<div id="leftcol"><?php include('TCNavi.inc'); ?></div>

<div id="content">

 

<form method="post" action="late.php" name="LateForm">

  <table style="width: 70%; text-align: left; margin-left: auto; margin-right: auto; font-family: Verdana;" border="0" cellpadding="2" cellspacing="2">

    <tbody>

      <tr style="font-weight: bold; color: rgb(255, 255, 255);" align="center">

        <td style="background-color: rgb(100, 149, 237);" colspan="2" rowspan="1"><big>Late Form</big></td>

      </tr>

      <tr>

        <td style="width: 30%;">PF #:</td>

        <td><input maxlength="10" size="10" name="empnum"></td>

      </tr>

      <tr>

        <td>Date:</td>

       

<td><?php date_default_timezone_set("Pacific/Tarawa");echo Date('Y-m-d'); ?>  <br><br>

 

</td>

 

      </tr>

      <tr>

        <td>Time In:</td>

        <td><?php echo date(' g:i A');echo "/"; echo date('H:i:s ',time()); ?>  </td>

      </tr>

   

      <tr>

   

        <td style="font-family: Verdana; width: 237px;">Late reasons:</td>

 

        <td style="width: 460px;"><textarea cols="35" rows="8" name="latereasons"></textarea></td>

 

    </tr>

   

      <tr align="center">

        <td style="width: 100%;" colspan="2" rowspan="1"><input value="SIGN-IN" name="Save"  type="submit" onclick="Validate();return false;"></td>

      </tr>

   

 

  </tbody>

  </table>

  <br>

</form>

</div>

 

<?php //echo (gmstrftime(" %H:%M:%S", mktime())); ?>  <br><br>

<?php //echo date('Y-m-d'); ?>  <br><br>

 

 

 

</body>

</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.