SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast subBlue's Avatar
    Join Date
    Jun 2001
    Location
    Edinburgh, UK
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynmic form buttons

    I have a form that has a set of buttons that i want to change the appearance of when they are clicked. I can do this by specifying the button name directly, but i'd like to be able to do it with dynamically. For example:

    I can do this:

    formObj.button1.value += "*";
    formObj.button2.value += "*";


    etc etc

    But i want to do something like this (which doesn't work!)

    whichbutton = "button" + bnumber;
    formObj[whichbutton].value += "*";


    I gues it doesn't work because i'm trying to specify an object with a standard variable, so how do i change it to make it work?

    Cheers.
    Become Interactive because its all gone a bit subBlue

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Tom,

    Use the eval() for what you want

    for (i=1; i <= numOfButtons; i++)
    {
    myButton = eval('document.formname.button' + i);
    myButton.value = "*";
    }

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •