Hi again Walter

> On 23 Jun 2019, at 16:09, Walter Lee Davis <wa...@wdstudio.com> wrote:
> 
> One of the best ways to work this out is to build a cut-down example, in one 
> page, that tries to do what you're after here. If you can get that to fail, 
> post it as a Gist or similar. From your description, you're going about 
> things the right way.

I’ve followed your advice to make a stripped-down version of the problem 
(though I’m afraid I’ve no idea what a Gist is), and it answered one of my two 
problems: there was something wrong with my XML (it may have been as basic as 
the wrong Content-type), so js ignored the response. However, it still won’t 
insert the new code where I want it (or indeed anywhere). I’ve narrowed it 
down, I’m pretty sure, to a problem of scope - and I’m sure it’s basic stuff. I 
don’t need to bore you with the very simple initial html or the even simpler 
code executed by the Ajax call, because I know that’s all fine now, but here’s 
the relevant js:

////////////

var base = 'http://10.0.1.2:90/~dvds/';

// initialization routines
document.observe ('dom:loaded', function() {
        // set up handler for variable numbers of selects
        var addselects = $$('.addselect');
        for (var i = 0; i < addselects.length; i++) {
                var addselect = addselects[i];
                addselect.onchange = newSelect;
        }
});

// handler for adding new field to array
function newSelect() {
//      var thisid = this.id;
        var newhtml;

        var url = base + 'ajaxtest';
        // send request to do the business
        var myAjax = new Ajax.Request (url, {
                method: 'post',
                onSuccess: function (req) {
                        var xml = req.responseXML;
                        var id = 
xml.getElementsByTagName('id')[0].firstChild.nodeValue;
                        
                        if (id) {
                                newhtml = '\t\t<li>\r\t\t\t<select 
class="addselect" name="newlist" id="newlist" />\r\t\t\t\t<option value="" 
selected="selected"></option>\r';
                                // loop
                                var newid, newname;
                                var ids = xml.getElementsByTagName('id');
                                var names = xml.getElementsByTagName('name');
                                for (var i = 0; i < ids.length; i++) {
                                        newid = ids[i].firstChild.nodeValue;
                                        newname = names[i].firstChild.nodeValue;
                                        newhtml += '\t\t\t\t<option value="' + 
newid + '">' + newname + '</option>\r';
                                }
                                newhtml += '\t\t\t</select>\r\t\t</li>\r';
//                              $('thisid').up('ul').insert (newhtml);
                        }
                        else {
                                alert (’ng');
                                newhtml = '<li>No good.</li>';
                        }
                },
                onFailure: function() {
                        alert ('Script failure.');
                        newhtml = '<li>No good.</li>';
                }
        });
        
// alert (newhtml);
        if (newhtml) {
                this.up('ul').insert (newhtml);
        }
}

////////////

What I need to do is /either/ make the value of the original ‘this' available 
to the inner part of the code (the line that’s commented out immediately after 
the last html += …) /or/ make newhtml available to the pouter part of the code 
for the 'if (newhtml)’ block at the end. But I can’t figure out how to do it 
because it doesn’t meet my normal assumptions about global and local variables.

I really feel I’m almost there with this problem - just this last hurdle to get 
over!

-- 
Cheers... Chris
Chris Sansom: composer and… whatnot
http://www.chrissansom.net/
https://www.youtube.com/channel/UCVUKb7vK0KiIaiLhs7zht2Q
https://soundcloud.com/mfthoad

‌Goodness is about what you do. Not who you pray to.‌
— Terry Pratchett‌

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prototype-scriptaculous+unsubscr...@googlegroups.com.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
Visit this group at https://groups.google.com/group/prototype-scriptaculous.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prototype-scriptaculous/5B879D02-856C-4BC0-B20D-3C6A039BC0B9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to