I don't think you can name variables as varname[name] and access them like
that in javascript unless
varname[name] is initialize where varname is an array and name=index in that
array and it must be defined first.

I believe you will have to change the naming convention from var[keyname] to
var_keyname or something, and same for reading it from PHP.

or else name them as:
input_1
input_2
input_...
input_N
then you can access them in JavaScript as:
for (i=0;i<n;i++)
{
fld=eval("form.input_"+i);
if (fld.value=="")
{
  alert('error in field');
  fld.focus();
}
}

as for PHP and reading them, you have to do:
<?
  for ($i=0;$i<$n;$i++)
{
  $temp = "input_$i";
  $value = $$temp;
  echo "value $i=$value";
}
?>

hope it helps.

-elias
http://www.kameelah.org/eassoft

"Joseph Blythe" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> G'day,
>
> I was wondering if anyone knows how to get the following to work:
>
> --snip from head--
> <script language="JavaScript">
> //-->
> 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--
>
> Now the above doesn't work as I think javascript does not understand
> arrays? or I don't understand how javascript deals with arrays??
>
> Any help/suggestions would be great, sorry if this post is a little off
> topic in the way of javascript but I would not be having this trouble if
> I weren't passing the form data to php via an array :-)
>
> Regards,
>
> Joseph.
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to