Click to See Complete Forum and Search --> : using javascripts with form array generated by PHP


Anon
10-31-2000, 04:10 AM
I have used php form element array with a html form as shown below

<form>
<?php
for($i=0;$i<6;$i++)
?>
<input type="text" name="empname[]" >
<?php
}
?>
</form>

this is working fine with php BUT the problem is I can't access this form array with javascript for client side validation.

Solution needed urgently. Please suggest.

Anon
10-31-2000, 07:18 AM
Urgent.... if I got a dime for every person who thinks his problem is "urgent".....

Javascript does not support arrays.
PHP only supports it as an feature.

You can get around it by not using arrays but using named variables instead.
call your inputs:
empname1 and empname2 etc.

in php you can get access them using "variable variables"
Check out the manual.

Anon
11-01-2000, 03:53 AM
Quick note on this, javascript does indeed support arrays, just not used as item names.

Simple solution to this problem would be to use a php script to verify the items on the page instead, not so hard to program and way more secure in that users can't just rewrite the code to get around it.

Personaly I like to have the forms page post to itself and if there are any problems with it then just simply place all the submitted items back in their respecive places and title that item in bold red print, or whatever colour is good for contrast on your background.

Anon
11-01-2000, 04:26 AM
"Quick note on this, javascript does indeed support arrays, just not used as item names."

Very true.
I meant to say just that! :)

Anon
11-01-2000, 07:38 AM
Thanks for your reply.
I am trying to get around with variable variables. Please notify me if you find any other solution.