If your JS code is more than two lines (on the basis that any code with more than 2 lines in it will have at least one bug, LOL!), I strongly suggest using the XX.js method, as described by felix in a previous post. So find your form's numeric ID (number in far left column of main forms list on the backend), and create ./components/com_fabrik/js/XX.js. In that, put ...
Code:
function myImageUpdate() {
var url = 'index.php?option=com_fabrik&format=raw&view=plugin&task=userAjax&method=getFigure';
var drill_id = $('mps_score___drill').getValue();
var update = $('mps_score___figure').firstChild;
var myTitle = $('mps_score___title');
new Request({
url: url,
data: {
method: 'getFigure', 'drill_id': drill_id
},
onComplete: function (r) {
update.src = "http://localhost/joomla" + r;
}
}).send();
}
NOTE - the only change I've made to this code is this.getValue() becomes $('mps_score___drill').getValue(), because 'this' is no longer in the right scope. You'll need to use your actual element name here, I'm just guessing.
Then in your element JS, instead of all the lines of code, just call ..
The reason for this is that it makes it a LOT easier to debug. You can now open up FireBug, go to the Script tab, locate XX.js on the Script menu, and put breakpoints in by just clicking in the left margin.
You can then make a change on your dropdown, and you'll be dropped in to the debugger at your breakpoint. From where you can see exactly what is going on, by looking at the Watch window on the right, which shows you all your variable values. You can step through the code line by line. You can put a breakpoint in the onComplete() function which will break when the AJAX response comes back from the server, and see exactly what 'r' is set to. And ... most helpfully, you can switch to the Console window whilst in a break point, and execute any line of code you want, to try it out, without having to modify the script and reload.
-- hugh