SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: array in forms

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Location
    Israel
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array in forms

    hi there
    i have an array in an HTML form.
    UserName[1], UserName[2]...
    all the UserName r actually a checkbox.
    now i need to disable them upon a disable button.
    in my function i created a loop
    for (Counter=1; Counter <=CheckMarkCounter; Counter++)
    //CheckMarkCounter is alredy set to something like 5.
    {
    document.Form1.UserName[Counter].disabled=true;
    }

    but that failed to work.
    so i tried
    to do the following, write the statment into a string and run it by using eval:

    st='document.Form1.UserName['+Counter+'].disabled=true';
    eval(st);

    as for the string, its fine but still the eval gives me an error: document.Form1.Username.1 is null or not an object....

    any1?
    thnx in advance
    You can't see your self in the mirror with your eyes closed!

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The eval would probably work using

    st=eval("document.Form1.UserName['+Counter+'].disabled=true");

    Always use double quote for start and end. But th\at may not be your problem.

    You ave them named username[9] etc...may not work. Javascript doesn't usually like array named form elements. Try removing the array elemtn and using username9 instead.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


Bookmarks

Posting Permissions

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