– xyz Feb 05 '11 at 18:48

  • 1
    if the function inside the ` – Crescent Fresh Feb 05 '11 at 21:00
  • 3 Answers3

    1

    Since you're updating the contents of an existing element you can both make use of Ajax.Updater and set it's evalScripts option. The script tag that gets inserted will be evaluated in the scope of the Ajax.Updater, meaning it can access functions that are global but not ones that are local to the script which started the update.

    Edit:
    You want a function contained in the script tag to exist in global scope. Instead of this:

    function somefunc() { ...
    

    You need to do it this way:

    somefunc = function() { ...
    

    And definitely don't use var as that prevents somefunc becoming a global variable. Later, when a button is clicked it's onclick event executes in global scope where somefunc now resides.

    clockworkgeek
    • 37,650
    • 9
    • 89
    • 127
    • "I would like to update content of div with code from top, not eval it." <- Don't want to evalScripts, i need them as – xyz Feb 05 '11 at 17:26
    0

    Nice article about experiments with innerHtml and script tags. It shouln't work but if SCRIPT tag has DEFER attribute then it will work under IE.

    gertas
    • 16,869
    • 1
    • 76
    • 58
    0

    Ok, sorry.

    Only thing that i needed to do was to declare var productSendtofriendForm before Ajax.Request... needed to bo global one.

    xyz
    • 2,277
    • 2
    • 25
    • 41