473,322 Members | 1,562 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,322 software developers and data experts.

Dynamic form validation with JavaScript

Hi,

I have a query that displays each row in a table. Each row is a form and I want to validate with JavaScript each form. How can I dynamically create functions ? Here's my code that does not work..

Thanks

Gilles

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. function noEntry2(form_name) {
  4. PER_DEB_01 = document.form_name.PER_DEB_01.value;
  5. PER_DEB_02 = document.form_name.PER_DEB_02.value;
  6. PER_DEB_03 = document.form_name.PER_DEB_03.value;
  7.  
  8. var PER_DEB = new Date(2008, 01, 01);
  9. var PER_DEB2 = new Date(document.form_name.PER_DEB_01.value, document.form_name.PER_DEB_02.value, document.form_name.PER_DEB_03.value);
  10.  
  11.  
  12. if ( (PER_DEB_01.length < 4) || (PER_DEB_02.length < 2) || (PER_DEB_03.length < 2) ) {
  13.     alert("bla bla bla");
  14.     document.form_name.PER_DEB_01.focus();
  15.     return false;
  16. }
  17. else if (PER_DEB2 < PER_DEB) {
  18.   alert("bla bla bla");
  19.   return false;
  20. }
  21.  
  22. }
  23.  
  24. function interval1(form_name) {
  25. var DT_DEB_02 = eval('document.'+form_name+'.PER_DEB_02.value');
  26.  
  27.     if (DT_DEB_02 < 1 || DT_DEB_02 > 12) {
  28.         alert("bla bla bla");
  29.         document.form_name.PER_DEB_02.value = ""; // NOT WORKING
  30.         return false;
  31.     }
  32.     else {
  33.         return true;
  34.     }    
  35. }
  36.  
  37. function interval2(form_name) {
  38. var DT_DEB_02 = eval('document.'+form_name+'.PER_DEB_03.value');
  39.  
  40.     if (DT_DEB_03 < 1 || DT_DEB_03 > 12) {
  41.         alert("bla bla bla");
  42.         document.form_name.PER_DEB_03.value = ""; // NOT WORKING
  43.         return false;
  44.     }
  45.     else {
  46.         return true;
  47.     }    
  48. }
  49.  
  50. //-->
  51. </script>
  52.  
  53.  
  54.  
  55.  
  56. <table width="98%" align="center" border="0" cellpadding="2" cellspacing="0">
  57.  
  58. <?php
  59. $ctr = 1;
  60. while ($recz3 = oci_fetch_array($z3)) {
  61. echo "
  62. <tr>
  63.     <form action='save.php' name='form".$ctr."' method='post' onSubmit='return noEntry2(form_name);'>
  64.     <td>".$recz3["MEDIA"]."</td>
  65.     <td>
  66.     <table border='0' cellspacing='0' cellpadding='0'>
  67.     <tr>
  68.         <td><input name='PER_DEB_01' value=".substr($recz3["PER_DEB"], 0, 4)." type='text' class='idDate' onKeyUp='return autoTab(this, 4, event);' size='4' maxlength='4' style='width: 40px;'></td>
  69.         <td>-</td>
  70.         <td><input name='PER_DEB_02' value=".substr($recz3["PER_DEB"], 5, 2)." type='text' class='idDate' onKeyUp='return autoTab(this, 2, event);' size='2' maxlength='2' style='width: 30px;'></td>
  71.         <td>-</td>
  72.         <td><input name='PER_DEB_03' value=".substr($recz3["PER_DEB"], 8, 2)." type='text' class='idDate' onKeyUp='return autoTab(this, 2, event);' size='2' maxlength='2' style='width: 30px;'></td>
  73.     </tr>
  74.     </table>
  75.     </td>
  76.     <td align='center'><input name='submit' type='image' value='save' src='images/icone_save_v4.gif'></td>
  77.     </form>
  78. </tr>
  79. ";
  80. $ctr++;
  81. }
  82. ?>
  83. </table>
  84.  
Dec 10 '08 #1
1 1778
acoder
16,027 Expert Mod 8TB
First step is:
Expand|Select|Wrap|Line Numbers
  1. document.forms[form_name]..
which will use the form name passed to the function rather than the literal "form_name" which most likely does not exist.
Dec 11 '08 #2

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

Similar topics

13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
11
by: brian.newman | last post by:
I'm trying to use a layer inside a form to hide/reveal a part of the form, but my code doesn't seem to be working and I need some help debugging it. I'm not getting an error which has made it...
2
by: iam247 | last post by:
Hi I have an ASP form which only includes an option list. The list is dynamically created but includes a default value, which is an instruction "Select a group". The code is shown at bottom....
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
1
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
1
by: kusanagihk | last post by:
To all, I'm working on a javascript to dynamic build a common set of HTML controls. 01) I've used the DOM object to build a <div> tag; then build 1 <input type='button'/> and 1 <input...
4
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
5
by: matt | last post by:
hello, i am on an interesting project. in this project, i have to create dynamic data-entry forms for offline-users to fill out, save locally, and eventually postback to our app (when back...
0
by: Steve Funk | last post by:
All, I have searched all around and have not yet found the answer to this nor a solution. Hopfully it will be easy to overcome. Here is what I am trying to do: I'm trying to build a wizard...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.