How to execute a statement in JS after concating it

Discussion in 'JavaScript' started by neurohari, Nov 21, 2005.

  1. #1
    Consider below JS statement

    UploadFrm.DropDownName.appendChild(myElement);

    I will be passing the value for "DropDownName" as arguement....

    I cannot staright the way use that variable "DropDownName" in that single line statement, its throwing out error

    so i did the concatination like below one,...

    var append = "UploadFrm." + DropDownName + ".appendChild(myElement)";

    How can i execute the statement which is stored as string in the variable "append".
     
    neurohari, Nov 21, 2005 IP
  2. neurohari

    neurohari Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello please, is anybody there to help me out?
    This may seem very very basic doubt......even silly...
    but I wonder if u cud help me out..

    is problem understandable??
     
    neurohari, Nov 21, 2005 IP
  3. BurgerKing

    BurgerKing Active Member

    Messages:
    397
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Hi,

    Not sure exactly what you are asking, but...

    If you are wanting to access a control that is passed by name, use:
    document.getElementById(DropDownName)

    If you are wanting to execute a javascript function, check out the eval function.
     
    BurgerKing, Nov 21, 2005 IP
  4. neurohari

    neurohari Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks a lot BurgerKing.

    I was just looking out for function like "eval"

    as i am being beginner for this JavaScript...i had struggled to get it done..

    As per your help a big messy code was commonised and reduced
     
    neurohari, Nov 22, 2005 IP
  5. execute

    execute Peon

    Messages:
    301
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    also can use
    var something = function() { a_pre_defined_function(Val, Val2) };
     
    execute, Nov 25, 2005 IP