Textbox Array Validation

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

Textbox Array Validation

Post 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
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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;
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Wait, you SAID checkbox but then your code only has text inputs. Oh well, you get the idea?
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

I am Sorry

Post by phppick »

Its not checkboxes.. TEXTBOXES.
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post 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
Post Reply