Web Analytics Made Easy -
StatCounter calling a function with parameters trough eval HELP im new at eval - CodingForum

Announcement

Collapse
No announcement yet.

calling a function with parameters trough eval HELP im new at eval

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • calling a function with parameters trough eval HELP im new at eval

    hello all,

    im new at using eval but i am trying to call a function with parameters trough the eval statement from a popup

    i have this

    app = //reference to the parent window
    _functionToCallWhenDone = "functiontocallonparent";

    eval(app + '.' + _functionToCallWhenDone + '("' + val + '");');

    i am using firefox by the way, its giving me this error

    missing ] after element list
    comunalpopup.js (line 130)
    [object Window].addSiteCalledFromPopUp("dan");

    i tried this
    eval([app + '.' + _functionToCallWhenDone + '("' + val + '");']);

    but that just doesnt error out but does not call the function either.

    has anyone encountered this before, any ideas?

    thanks in advance

    -daniel

  • #2
    When app is concatenated with "." via the + operation app.toString() is returning the string "[object Window]". This causes an error because "[object Window].functiontocallonparent" makes no sense.

    Most times eval is not required:
    Code:
    app = //reference to the parent winow
    app.functiontocallonparent(val);
    If you insist on using eval, include app in quotes.
    Code:
    eval('app.' + _functionToCallWhenDone + '("' + val + '");');
    Be careful that the string returned from val.toString() returns a valid argument for _functionToCallWhenDone.
    Last edited by VortexCortex; Oct 7, 2006, 04:32 AM. Reason: clarification.

    Comment

    Working...
    X