Page 1 of 1

Textbox Array Validation

Posted: Mon Mar 01, 2004 2:51 am
by phppick
I want to validate this Form. I need each and every checkbox to be filled.
anybody can help?

<html>
<head>
<title>Title</title>
</head>
<body>
<form name="the_form" method="post" action="">
<table>
<tr><td><input type="submit" value="Create Record" /></td></tr>
<tr><td> </td></tr>
<tr>
<td>Text box 1</td>
<td><input type="text" value="1" name="textbox[1]" /></td>
</tr>
<tr>
<td>Text box 2</td>
<td><input type="text" value="2" name="textbox[2]" /></td>
</tr>
<tr>
<td>Text box 3</td>
<td><input type="text" value="3" name="textbox[3]" /></td>
</tr>
...
...
...
...
<tr>
<td>Text box N</td>
<td><input type="text" value="N" name="textbox[N]" /></td>
</tr>
</table>
</form>
</body>
</html>

Thanks.
Jen

Posted: Mon Mar 01, 2004 5:21 pm
by Unipus
Something like:

Code: Select all

function validatethis()
&#123;
var theFormElems = document.forms.the_form.getElementsByTagName('input');
for (var i = 0; i < theFormElems.length; i++) 
&#123;
	if (theFormElems&#1111;i].type == "checkbox" && theFormElems&#1111;i].checked != "true")
	&#123;
		alert("BAD KITTY!");
		return false;
	&#125;
&#125;
&#125;

Posted: Mon Mar 01, 2004 5:23 pm
by Unipus
Wait, you SAID checkbox but then your code only has text inputs. Oh well, you get the idea?

I am Sorry

Posted: Mon Mar 01, 2004 11:46 pm
by phppick
Its not checkboxes.. TEXTBOXES.

Posted: Tue Mar 02, 2004 8:14 pm
by ilovetoast
Use the base validation scripts I posted previously here.

For each textbox in the form 1, 2, 3, ... N add a validation definition according to the following structure:

Code: Select all

var validation_definitions= 
       &#1111; 
          &#1111;// submit button (not always first - just first in this form) 
             &#1111; 
                // No validation on submit button. 
             ] 
          ], 
          &#1111;// textbox&#1111;1] 
             &#1111; 
                &#1111;&#1111;"req"], "ERROR: You forgot item 1."] 
             ] 
          ], 
          &#1111;// textbox&#1111;2] 
             &#1111; 
                &#1111;&#1111;"req"], "ERROR: You forgot item 2."] 
             ] 
          ], 
          &#1111;// textbox&#1111;3] 
             &#1111; 
                &#1111;&#1111;"req"], "ERROR: You forgot item 3."] 
             ] 
          ],
          ....
          &#1111;// textbox&#1111;N] 
             &#1111; 
                &#1111;&#1111;"req"], "ERROR: You forgot item N."] 
             ] 
          ]
       ];
peace