With apologies in advance for the length...

I retired a few years ago from web development, where I used Prototype 
quite a bit in the later years. I'm somewhat rusty now, but I'm trying to 
do some development for purely personal use. It won't be on the open web, 
just on our local server. It's all been going fine (if slowly!), but now 
I've hit a brick wall with Ajax.

Here's what I'm trying to do:
*  I have a form with one or more <select>s, each within its own <li>, all 
in the one <ul>.
*  Each <select> contains the same list of items from a table in a MySQL 
database.
*  The last <select> has nothing selected and has the class "addselect".
*  The idea is that if I select something from that last <select>, an 
onChange event is triggered which calls an Ajax script to add a new 
<select> (containing the same items). This is set up on page load in a 
"document.observe ('dom:loaded', function()..." at the top of the 
javascript file.
*  Each <select> has a sequential name and id, eg 'name="country[0]" 
id="country_0"', the next country[1] and country_1, and so on. The newly 
created <select> would have the next name and id in sequence.
I hope that all makes some sense.

So...
The handler function set up in 'dom:loaded...' gets the next index number 
for the name and id of the new <select>, and sends this ('entryindex') and 
the name of the table to search ('list') to the Ajax script, and off we go:

var pars = 'list=' + list + '&entryindex=' + newIndex;
var url = base + 'ajaxgetmenu';
// send request to do the business
var myAjax = new Ajax.Request (url, {
method: 'post',
parameters: pars,
onSuccess: function (req) {
var xml = req.responseText;
...

This far, everything is hunkydory. Safari's Web Inspector shows exactly the 
correct result - a nice new <select> with the correct name and contents - 
under 'XHRs' in its Resources tab. So I know the script is being called and 
is operating correctly. But where it falls over is with what comes next:

var newhtml = xml.getElementsByTagName('newhtml')[0].firstChild.nodeValue;

This, incidentally, is taken from a script I developed back in my 
professional days which I know worked perfectly. But something is failing 
here, cuz it don't work! If I put an alert in ('ok') before this line, it 
pops up, but if I put it after this line it doesn't. And yet no errors are 
reported. And of course the next line doesn't work either:

$('thisid').up('ul').insert (newhtml);

(And I know "$('thisid')" is right because I put that in an alert to check 
it.)

So I simplified it. I abandoned XML and made the result plain text instead, 
to be inserted verbatim. Again, the script produces a perfect result in 
Safari's Web Inspector, but even when newhtml is plain text (and I skip the 
xml.getElementsByTagName line altogether), it fails. And again, an alert 
before the insert line works, but not one after it.

I've tried everything I can think of, so if anyone has any wisdom on this 
I'd be very grateful indeed. It's probably something dead obvious staring 
me in the face...

-- 
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/fb84d882-af7d-45f8-a400-b98701228f19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to