mweinberger Posted February 9, 2007 Share Posted February 9, 2007 Hi All, Suppose I have the following text box elements: <p>Please enter text into the two boxes below.</p> <input type="text" ID="MyID[]", NAME="MyID[]" /> <input type="text" ID="MyID[]", NAME="MyID[]" /> In PHP the posted data will come in as $_POST["MyID"] as an array, which I can then enumerate using a foreach loop. My questions is how would I access these same elements from JavaScript. The standard JavaScript code: var strText1, strText2; var objMyTextValue1, objMyTextValue2; objMyTextValue1 = document.getElementById("MyID[]"); objMyTextValue2 = document.getElementById("MyID[]"); strText1 = objMyTextValue1.value; strText2 = objMyTextValue2.value; The JavaScript code that sets objMyTextValue1 and objMyTextValue2 is obviously missing something. What would the correct code be? Thank you in advance, Marci Weinberger ButterflyVista Link to comment https://forums.phpfreaks.com/topic/37820-php-element-control-array-and-javascript-accessing-them/ Share on other sites More sharing options...
camdagr81 Posted February 9, 2007 Share Posted February 9, 2007 you can use a <?php ?> tag in your javascript just like in the html sections. Just be sure to save your page as a .php file for instance: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>test.php</title> <script type="text/javascript"> var test = "<?php echo 'HELLO WORLD'; ?>"; document.write(test); </script> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/37820-php-element-control-array-and-javascript-accessing-them/#findComment-181005 Share on other sites More sharing options...
mweinberger Posted February 9, 2007 Author Share Posted February 9, 2007 I appreciate the reply, but how does that answer my question? Thanks, Marci Link to comment https://forums.phpfreaks.com/topic/37820-php-element-control-array-and-javascript-accessing-them/#findComment-181012 Share on other sites More sharing options...
camdagr81 Posted February 14, 2007 Share Posted February 14, 2007 you would create a javascript control that uses the data posted in an array. I was jus showing you how you could write the javascript with php code, thus making your javascript dynamic at the page load. It's up to you to apply said knowledge Link to comment https://forums.phpfreaks.com/topic/37820-php-element-control-array-and-javascript-accessing-them/#findComment-184795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.