views:

674

answers:

2

Hi.

I have a form, and there are 5 fields. The first field is an autocomplete field. I'd like to have the other 4 fields populated based on the autocomplete field selection. The docs in github ajax.autocompleter page reference setting an id and using a js function to call the id value, but this doesn't seem efficient if using multiple fields/need multiple values in addition to the ac value.

I'm using scriptaculous, and php. I have the autocompleter functioning, but am not sure on the rest of it. I'm also not clear on how to set the additional field parameters on the php end. I suppose that I could set the id="field1Val='blah'&field2Val='blah2'" then use js to parse and populate fields, but something about that just doesn't feel right.

Any idears?

A: 

Eh, I just did it with the id field...

stormdrain
A: 

this is what we use: a jquery plugin. The good thing about this one is that you can add a callback function that allow you to change the "current" behavior.

about the line 385 you have function that parses the result:

function parse(data) {
 var parsed = [];
 var rows = data.split("\n");
 for (var i=0; i < rows.length; i++) {
  var row = $.trim(rows[i]);
  if (row) {
   row = row.split("|");
   parsed[parsed.length] = {
    data: row,
    value: row[0],
    result: options.formatResult && options.formatResult(row, row[0]) || row[0]
   };
  }
 }
 return parsed;
};

you can create your own function that depending on what you get (you can send a json from the server) and then execute javascript and drive the form controls.

hope help you

Gabriel Sosa