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

    javasctipt and forms with array fields

    i can use a command such as ->

    PHP Code:
    window.document.demo.test.value "updated1"
    to update a text field in a form like ->

    PHP Code:
    <input name="test" type="text"

    However i want to start using array fields like ->

    PHP Code:
    <input name="test[]" type="text"
    But cant work out what i would need in javascript to do the same, any ideas?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Warning: brackets in a name can lead to interesting dilemmas later.
    I'm not sure if they are valid html. Might be. Might not be. You might want to check before you start using that. If it isn't valid, some browsers might puke.

    That said:
    document.demo.elements["test[]"].value="whatever";

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers for that mike, works a treat..

    i did read on php.net they are used to pass an array though from a form, to php, appose to say having a list of names and passing all that data across thought the url. So long as that holds up i am fine, as the data gets saves in a database.

    Thanks for your help...

  • #4
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    seem to have found a problem, when using a for next loop.

    this works fine.
    PHP Code:
    document.demo.elements["test[1]"].value="whatever"
    however this wont
    PHP Code:
    var 1;
    document.demo.elements["test[i]"].value="whatever"

    any ideas????
    Last edited by anubis; 09-20-2005 at 05:45 PM.

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    It's a string. It is not evaluated as a number. Unless...

    document.demo.elements["test["+i+"]"].value="whatever";


    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #6
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts


    cheers... at last...... you've been very helpfull, cheers


  •  

    Posting Permissions

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