View Full Version : Accessing Array variables

07-23-2002, 02:07 PM
The first section below is PHP which simply outputs some HTML form components (2 selects and 2 texts). Each of these components are named as arrays as they are generated inside a for loop which works fine. My problem is that I cant access the components using the HTML line at the end of my code in the normal way. All I want to do is set the 'signUpListLocation[]' component's value to 'empty string' but I'm not sure about the syntax of accessing the array variable. Suggestions most welcome...




for ($i = 0; $i < $numSessions; $i++)
echo("<TR><TD><SELECT NAME='signUpListDay[]'>");
echo("<TD><SELECT NAME='signUpListTime[]'>");
echo("<TD><INPUT TYPE=TEXT NAME='signUpListLocation[]' SIZE=40></TD>");
echo("<TD><INPUT TYPE=TEXT NAME='signUpListWeeks[]' SIZE=15></TD>");

<TD><a href='#' onMouseOver="window.document.newForm.signUpListLocation[0].value='empty string';">Reset</a></TD></TR>


07-23-2002, 07:10 PM
Because you have your form elements named in a way that Javascript can't validly access as an object, you'll have to access it as a string:

window.document.newForm.elements['signUpListLocation[]'].value='empty string'


Anyway, this is more appropriate in the Javascript programming forum, so I'll move it there.