ppetree 2 Junior Poster

I have a block of code from a prototype.js (ajax code) sample and I want to modify it in order to isolate a piece of the code to make it more maintainable:

The original code looks like this (red is what I want to move):

function dofill( ) {
  new Ajax.Updater( 'result', 'getdata.php', { method: 'post', parameters: $('myform').serialize(),
  onSuccess: function( transport ) {
  $('elFirst').value = transport.responseXML.getElementsByTagName('first')[0].firstChild.nodeValue;
  $('elLast').value = transport.responseXML.getElementsByTagName('last')[0].firstChild.nodeValue;
  $('elEmail').value = transport.responseXML.getElementsByTagName('email')[0].firstChild.nodeValue;
  } } );
}

What I created was this:

function fillin() {
  $('elFirst').value = transport.responseXML.getElementsByTagName('first')[0].firstChild.nodeValue;
  $('elLast').value = transport.responseXML.getElementsByTagName('last')[0].firstChild.nodeValue;
  $('elEmail').value = transport.responseXML.getElementsByTagName('email')[0].firstChild.nodeValue;
}

function dofill() {
  new Ajax.Updater( 'result', 'getdata.php', { method: 'post', parameters: $('myform').serialize(),
  onSuccess: [B]fillin[/B] } );
}

I have also tried:

function fillin() {
  $('elFirst').value = transport.responseXML.getElementsByTagName('first')[0].firstChild.nodeValue;
  $('elLast').value = transport.responseXML.getElementsByTagName('last')[0].firstChild.nodeValue;
  $('elEmail').value = transport.responseXML.getElementsByTagName('email')[0].firstChild.nodeValue;
}

function dofill() {
  new Ajax.Updater( 'result', 'getdata.php', { method: 'post', parameters: $('myform').serialize(),
  onSuccess: [B]fillin()[/B] } );
}

Either way, I'm getting an error that fillin() is not defined. What's the proper way to isolate this into a seperate function?

Thanks,

Pete

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.