469,324 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,324 developers. It's quick & easy.

Mandatory Fields

OK so its been a while since I have had to put some field checking code together, I thought what I had done was fairly simple but nothing ever is, is it!?

This my script code:

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3.     function validate(frm) 
  4.     {
  5.         if (frm.lb_dept.value.length == 0)
  6.         {
  7.             alert("Please enter a Requestors Department.")
  8.             frm.lb_dept.focus()
  9.             return false
  10.         }
  11.  
  12.         if (frm.lb_sub_dept.value.length == 0)
  13.         {
  14.             alert("Please enter a Requestors Sub-Departmen.")
  15.             frm.lb_sub_dept.focus()
  16.             return false
  17.         }
  18.  
  19.         if (frm.lb_type.value.length == 0)
  20.         {
  21.             alert("Please enter a Request Type.")
  22.             frm.lb_type.focus()
  23.             return false
  24.         }
  25.  
  26.         if (frm.lb_priority.value.length == 0)
  27.         {
  28.             alert("Please enter a Request Priority.")
  29.             frm.lb_priority.focus()
  30.             return false
  31.         }
  32.  
  33.         if (frm.target_date.value.length == 0)
  34.         {
  35.             alert("Please enter a Target Date .")
  36.             frm.target_date.focus()
  37.             return false
  38.         }
  39.     }
  40. //-->
  41. </SCRIPT> 
So I check the length of 5 fields and return false if they are 0.

This is the first line of my form:

[HTML]<form id="logcallform" name="logcallform" method="POST" onsubmit="return validate(logcallform)" action="php/xmlhttp/logcall.submit.php">[/HTML]
My validation function never seems to get called!

I am a not 100% sure if I can leave the action tag in the form of if I need to put that in an else tag within the validation code?

Any help is much appreciated.
Nov 19 '07 #1
1 1125
gits
5,390 Expert Mod 4TB
hi ...

welcome to TSDN ...

try:

Expand|Select|Wrap|Line Numbers
  1. <form id="logcallform" name="logcallform" method="POST" onsubmit="return validate(this)" action="php/xmlhttp/logcall.submit.php">
that way we pass the correct reference to the form itself

kind regards
Nov 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by AR123 | last post: by
6 posts views Thread by Dameon99 | last post: by
1 post views Thread by ajd335 | last post: by
pradeepjain
1 post views Thread by pradeepjain | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.