ppetree 2 Junior Poster

I've started with the samples included with prototype.js which has the following code in the fillin example (a portion of which I want to isolate into its own function).

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

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 fill_in(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;
}
function dofill() {
  new Ajax.Updater( 'result', 'getdata.php', { method: 'post', parameters: $('myform').serialize(),
  onSuccess: function ( transport ){
      fill_in(transport);
  } } );
}

I cant seem to get this to work... but I'm not getting any errors either. The idea is to make the fill_in() independent so that it can be easily changed and updated and this allows the dofill() to be stuck in a .js file.

I dont understand why transport wont just pass as a variable. How do I do this?

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.