Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Glasgow, Scotland
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing Array variables

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

    Martin


    <HTML>

    <?PHP
    $numSession=8;

    for ($i = 0; $i < $numSessions; $i++)
    {
    echo("<TR><TD><SELECT NAME='signUpListDay[]'>");
    echoDays();
    echo("</SELECT></TD>");
    echo("<TD><SELECT NAME='signUpListTime[]'>");
    echoTimes();
    echo("</SELECT></TD>");
    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>

    </HTML>

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •