Re: How to index HTML fields for Javascript and PHP at same time?

From: Date: Tue, 04 Sep 2001 02:47:31 +0000
Subject: Re: How to index HTML fields for Javascript and PHP at same time?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65825@lists.php.net to get a copy of this message
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

« previous php.general (#65825) next »