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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Modifying an item in an array of text boxes

    I have an array of textboxes that is created dynamically using PHP. The text boxes are called description[X] where X is an integer from 0. Also generated is an array of buttons called delete[X] where X is the same integer.

    I basically need a function that, when delete[X] is pressed, changes the value of description[X] to a certain string ("DELETED", for example) so that I can play around with it in PHP.

    Try as I might, and after frantic searching through my JavaScript in 24 hours book, I still can't work out how to do it. Please help!
    Last edited by dunce; 09-26-2005 at 01:34 PM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts

    Use javascript square bracket notation

    Code:
    <script type="text/javascript">
    function deleteDesc(index, oForm){
       oForm.elements["description["+index+"]"].value = "DELETED";
    }
    </script>
    ...
    <form>
    <input type="button" name="delete[0]" value="Delete" onclick="deleteDesc(0, this.form)" />
    <input type="button" name="delete[1]" value="Delete" onclick="deleteDesc(1, this.form)" />
    
    <input type="text" name="description[0]" />
    <input type="text" name="description[1]" />
    ...
    </form>
    See my sig for more info of square bracket notation.

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works perfectly! Thanks a lot!


  •  

    Posting Permissions

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