Hi,

Really close. :-)  But you're running afoul of how eval handles the
var statement.  (If you'd just left the var statement out entirely, it
probably would have worked thanks to the horror of implicit globals
[1], but you'd be cluttering up the window namespace something
fierce.)  Also,  you're repeating a lot of code.

Instead, I'd suggest declaring a hash of editors on your main page
(not the stuff loaded dynamically) and a function for adding or
replacing one; and may as well wrap those up into just the one global
symbol:

In your main script:
* * * *
var ipeManager = {
    editors: {},

    addOrReplaceEditor: function(id, url, size, paramstr) {
        var eds;

        eds = this.editors;

        if (eds[id]) {
            eds[id].dispose();
            eds[id] = undefined; // Or: delete eds[id];
        }

        eds[id] = new Ajax.InPlaceEditor(
            id,
            url,
            {
                size: size,
                callback: function(form, value) {
                    return paramstr + escape(value);
                }
            }
        );
    }
};
* * * *

Then the dynamic stuff can be much simpler:
* * * *
<div id="kwdisp0101">some keyword</div>
<script>
ipeManager.addOrReplaceEditor(
   "kwdisp0101",
   './addkw.php',
   17,
   'oldwd=some%20keyword&idx=section-id&myparam='
);
</script>
* * * *

[1] http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On Jul 30, 5:51 pm, Drum <[email protected]> wrote:
> Ok, thanks. I think I understand the reasoning here, but I can't get
> my actual example to work.
>
> This is the script as it appears in the initially loaded page and also
> as it is in the html snippets bought in by ajax.
>
> <div id="kwdisp0101">some keyword</div>
>
> <script>
> if(editor0101){
> editor0101.dispose();
> editor0101 = undefined;}
>
> var editor0101;
> editor0101 = new Ajax.InPlaceEditor('kwdisp0101','./addkw.php',{size:
> 17,callback: function(form, value) { return 'oldwd=some
> %20keyword&idx=section-id&myparam=' + escape(value)}});\n";
> </script>
>
> The 0101 is an example, I do this for each keyword in the list and
> derive the numbers from some php code, net will be 0102, 0103 0201
> 0202 &c. This goes for both the editor var name in the js, and for the
> dic id in the HTML.
>
> Have I missed or misunderstood something? (it's been a long day...)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to