On Mon, 3 Sep 2001, Miguel wrote:

> I need to refer these fields like vector in PHP and Javascript mode.
> When I write <input type=text name=myfield[]... > then I can see values
> in PHP sccript, BUT can't see values in javascript mode, thats to say
> document.form.myfield[index].value doesnt work.
> On the other side, when I make <input type=text name=myfield....> I can
> see indexed values in Javascript BUT not in PHP script.

Try giving the input fields id's that you can use from JavaScript.

i.e.- <input type="text" id="field1" name="myfield[]">

then from your JavaScript, you can refer to that field by referencing
document.myForm.field1.value (for Netscape and IE)
And you can still use $myField[] in PHP.


Check out this small test ...

// HTML FORM

<html>
 <head>
  <title>Test</title>
  <script language="JavaScript">
   function setField( ){
    document.testForm.field1.value = "Woot!";
    document.testForm.field2.value = "I Really Hope";
    document.testForm.field3.value = "This Works For You!";
   }
  </script>
 </head>
 <body>
  <form name="testForm" action="test.php" method="POST">
   <input type="text" id="field1" name="myfield[]" value="">
   <input type="text" id="field2" name="myfield[]" value="">
   <input type="text" id="field3" name="myfield[]" value="">
   <input type="button" onClick="setField()" value="Click!">
  </form>
 </body>
</html>

// PHP Form Handler (test.php)
for( $i = 0; $i < sizeof( $myfield ); $i++ ){
        print( $myfield[$i] );
}


(Step through the array any way you please :)

        ~Chris                           /"\
                                         \ /     Pine Ribbon Campaign
Microsoft Security Specialist             X      Against Outlook
The moron in Oxymoron.                   / \     http://www.thebackrow.net


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