Re: validating form data via javaScript when stored in an array

From: Date: Mon, 09 Apr 2001 08:09:43 +0000
Subject: Re: validating form data via javaScript when stored in an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47743@lists.php.net to get a copy of this message
Morten Winkler Jørgensen wrote:
You will have to declare <SCRIPT LANGUAGE="javascript 1.2">
      myArray  = new Array();
      myArray[0] = "a string";
      myArray[1] = 11;
      myArray[2] = new Array();
</SCRIPT> since JavaScript 1.2 has arrays implemented. Thanks for that, but my problem being that I have just collected all my form data in an array:
input[keyname] how do I now build the equivelent js array to validate the data? I tried the following still does not work: --snip from head-- <script language="JavaScript1.2"> //--> input = new Array(); function validateForm(theForm) { if ( theForm.input[name].value == "" ) { alert("You must type a value for NAME."); theForm.input[name].focus(); return false; } } <!-- </script> --/snip-- --snip from body--- <form name="form" method="post" action="whatever" onSubmit="return validateForm(this);"> <input type="text" name="input[name]"> <input type="text" name="input[address]"> <input type="submit" value="submit"> </form> --/snip-- How do I force all the data into the javascript array, while still setting the array to input[keyname]? Any help appreciated, Regards Joseph

« previous php.general (#47743) next »