473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

error check before form submission

59
Hello,

It should be working but for some reasons it's not.

Expand|Select|Wrap|Line Numbers
  1. function Validator(frmname)
  2. {
  3.   this.formobj=document.forms[frmname];
  4.     if(!this.formobj)
  5.     {
  6.       alert("BUG: couldnot get Form object "+frmname);
  7.         return;
  8.     }
  9.     if(this.formobj.onsubmit)
  10.     {
  11.      this.formobj.old_onsubmit = this.formobj.onsubmit;
  12.      this.formobj.onsubmit=null;
  13.     }
  14.     else
  15.     {
  16.      this.formobj.old_onsubmit = null;
  17.     }
  18.     this.formobj.onsubmit=form_submit_handler;
  19.     this.setAddnlValidationFunction=set_addnl_vfunction;
  20.     this.clearAllValidations = clear_all_validations;
  21. }
  22.  
  23. function set_addnl_vfunction(functionname)
  24. {
  25.   this.formobj.addnlvalidation = functionname;
  26. }
  27.  
  28. function clear_all_validations()
  29. {
  30.     for(var itr=0;itr < this.formobj.elements.length;itr++)
  31.     {
  32.         this.formobj.elements[itr].validationset = null;
  33.     }
  34. }
  35.  
  36. function form_submit_handler()
  37. {
  38.     for(var itr=0;itr < this.elements.length;itr++)
  39.     {
  40.         if(this.elements[itr].validationset &&
  41.        !this.elements[itr].validationset.validate())
  42.         {
  43.           return false;
  44.         }
  45.     }
  46.     if(this.addnlvalidation)
  47.     {
  48.       str =" var ret = "+this.addnlvalidation+"()";
  49.       eval(str);
  50.     if(!ret) return ret;
  51.     }
  52.     return true;
  53. }
  54.  
  55. function uploaderError()
  56. {
  57.   var frm = document.forms["upload"];
  58.  
  59.   var uplSplit = frm.filePath.value.match("^(.+).(.+)$");
  60.   if (uplSplit == null) { ErrorPath(); return false; }
  61.  
  62.   if (uplSplit[2] != null )
  63.   {
  64.      if ((uplSplit[2].match("gif") == null) || (uplSplit[2].match("jpg") == null) || (uplSplit[2].match("jpg") == null))
  65.      { ErrorPath(); return false; }
  66.      else { return true; }
  67.   }
  68.  
  69.  
  70.   if (frm.filePath.value == '')
  71.   {
  72.      ErrorPath();
  73.      return false;
  74.   }
  75.   else if ((frm.Title.value == '') || (strlen(frm.Title.value) > 15))
  76.   {
  77.      ErrorTitle();
  78.      return false;
  79.   }
  80.   else if ((frm.height.value != '') && (frm.width.value == ''))
  81.   {
  82.      Errorresize();
  83.      return false;
  84.   }
  85.   else if ((frm.hieght.value != '') && (frm.width.value == ''))
  86.   {
  87.      Errorresize();
  88.      return false;
  89.   }
  90.   else if ((frm.pincode.value != '') && (frm.memid.value == ''))
  91.   {
  92.      ErrorMem();
  93.      return false;
  94.   }
  95.   else if ((frm.memid.value != '') && (frm.pincode.value == ''))
  96.   {
  97.      ErrorMem();
  98.      return false;
  99.   }
  100.   else
  101.   {
  102.      return true;
  103.   }
  104. }
Expand|Select|Wrap|Line Numbers
  1. <form action="process.php" method="post" name="upload">
outside form

Expand|Select|Wrap|Line Numbers
  1. </form>
  2. <script language="JavaScript" type="text/javascript">
  3.  var frmCheck  = new Validator("upload");
  4.  frmCheck.setAddnlValidationFunction("uploaderError");
  5. </script>
form name is "upload". The problem is, it's not going through the checks.

Thanks in Advace.
Jul 12 '07 #1
8 2870
cssExp
59
could anyone here help? ...is it that impossible to do error check on submit?
Jul 13 '07 #2
acoder
16,027 Expert Mod 8TB
onsubmit must return true or false.

Do you get any errors?
Jul 14 '07 #3
cssExp
59
onsubmit must return true or false.

Do you get any errors?
the problem is it's not going through the checks.. even when i put onSubmit in form directly in the following way.

Expand|Select|Wrap|Line Numbers
  1. function eCheck()
  2. {
  3.  var filePath = getElementbyId('filePath');
  4.  
  5.  if (filePath == '')
  6.  {
  7.  alert('This is not valid');
  8.   return false;
  9.  }
  10.  else
  11.  {
  12.   return true;
  13.  }
and
Expand|Select|Wrap|Line Numbers
  1. <form action="process.php" method="post" onSubmit="return eChek()">
above is not related to the mentioned script. but it shows that its not going through 'if'. Don't know why.
Jul 15 '07 #4
gits
5,390 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. getElementById() 
  2.  
is case senstive
Jul 15 '07 #5
cssExp
59
Expand|Select|Wrap|Line Numbers
  1. getElementById() 
  2.  
is case senstive
yes i know that, i mistyped it here. i did use getElementById
Jul 15 '07 #6
gits
5,390 Expert Mod 4TB
aaarrgh ... i missed that simple mistake you made ;) sorry ... you have to compare the value of course:

Expand|Select|Wrap|Line Numbers
  1. var filePath = document.getElementById('filePath').value;
kind regards ...
Jul 16 '07 #7
cssExp
59
great! it works!, but why doesn't the script that my twin wrote not working (one in the main post)
Jul 16 '07 #8
gits
5,390 Expert Mod 4TB
hi ...

i bet that is the typical problem with doing script-things during load ... ;) i always recommend to start all javascript-activities that refer to page-elements with the onload-handler of the document's body. during load the document dom isn't reliable ready ... onload it is ... try this and i think it should work that way ;))

kind regards
Jul 16 '07 #9

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

Similar topics

8
by: Polar | last post by:
I am having troubles finding the parse error in this script. I've been checking for weeks. I am too new to the subject I guess. I am trying to show a readord and them have a form at the bottom...
3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
6
by: WindAndWaves | last post by:
Hi Gurus The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error. I really have no idea where that is...
5
by: Jurgen Defurne | last post by:
I am currently designing an application which should be accessible from different interfaces. For this I like to be using stored procedures to process the contents of form submissions and dialog...
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
6
mmarif4u
by: mmarif4u | last post by:
Hi everyone. i make a page that a user input thier icnumber with confirm ic number, it saves the data to mysql db with current date and a random access code generated automatically, NOW i have...
0
by: kammaldeep | last post by:
hi, i m newbie 2 PHP & to b frank ... will alwaz be ... i dont think i will go into much details with PHP as my work doesnot include workin with PHP bt i have a forum .. and i want to make a...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
1
by: skyy | last post by:
Hi, Is there any way to check the status of a form submission using javascript? Check whether the form submission is finished? thanks!
2
by: dancerman | last post by:
I want a simple as possible regex to check the format of my form submission URL string, I don't care whether is an actual real working URL, just that it be in proper URL format and, IF POSSIBLE add...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.