Finally got this working. For those people who are interested:
1. In CaseStudyPage.php I added this:
Requirements::javascript("bclweb/javascript/getBrand.js");
2. I then created the above javascript file, which uses the same prototype library already running in the cms (a bit depreciated)
header = '<label for="Form_EditForm_BrandID" class="left">Brand</label><div class="middleColumn">';
footer = '</div>'
Behaviour.register({
'#Form_EditForm_ClientID' : {
onchange : function() {
backupHTML = $('BrandID').innerHTML;
$('BrandID').innerHTML = header + "loading brands <img src='cms/images/network-save.gif' alt='loading' />" + footer;
new Ajax.Request('/myadmin/getBrands/?clientid='+this.value,
{
method:'get',
onSuccess: function(transport){
var response = transport.responseText || "no response text";
if(response!="false"){
$('BrandID').innerHTML = header + response + footer;
}else{
$('BrandID').innerHTML = header + "there was a problem while loading brands. Please refresh the page and try again." + footer;
}
},
onFailure: function(){ $('BrandID').innerHTML = backupHTML}
});
}
}
});
3. Finally, I created an Admin controller which entends LeftAndMain, just adding a new custom method
class MyAdmin extends LeftAndMain {
/**
* Form that will be shown when we open one of the items
*/
public function getBrands() {
if(isset($_GET['clientid'])&&$_GET['clientid']!=""){
if($brands = DataObject::get("Brand","ClientID = ".Convert::raw2sql($_GET['clientid']))){
$brands = $brands->toDropdownMap();
$dropdown = new DropdownField('BrandID','Brand',$brands);
$dropdown->setEmptyString("Please select");
}
else{
$dropdown = new DropdownField('BrandID','Brand',array());
$dropdown->setEmptyString("There are no brands available for this client");
return($dropdown->forTemplate());
}
return($dropdown->forTemplate());
}
return "false";
}
}
Hope this helps someone!
I think it would be nice to keep the javascript libraries up to date, because I know I can make this a little better, by getting rid of the harcoded header and footer wrapper, but it was more complex to get the specific bit of html i needed using 1.4 of prototype. 1.6 seems to have some beter selection functions. I prefer JQuery anyway, but for the sake of not wanting to cause JS collisions I went with Prototype in this case.