I have the following view:
<form action=<?=$target;?> method="post" name="editForm">
<div id="page1">
<select id="categories" name="category" onmouseover="populateCategory(<?=$result?>, <?=$id?>)" >
</select>
</div>
</form>
which utilizes the following javascript function on the select tag:
function populateCategory(subCategories, id) {
var select = document.getElementById(id);
var opt = document.createElement("option");
opt.text = "--Please make a selection--";
for (i = 0; i < subCategories.length; i++) {
var opt = document.createElement("option");
opt.value = i;
opt.text = subCategories[i];
select.add(opt);
}
}
The arguments passed to the function are the following variables:
$result = $this->getCategories(0);
$id = 'categories';
which calls the following function
public function getCategories($parent, $published = 1) {
//Sanitize Params...
//$sanParent = $this->db->getEscaped($parent);
//$sanPublished = $this->db->getEscaped($published);
$query =
"SELECT * FROM #__adsmanager_categories
WHERE parent = " . $parent .
" AND published = " . $published;
$this->db->setQuery($query);
$result = $this->db->loadAssocList();
var_dump($parent);
if (!$result) {
return false;
}
return $result;
}
The low-down:
The last function I posted makes a request to a database, obtaining a list of categories which are intended to be used to create a dropdown list. I thought that if I passed the obtained categories to the JavaScript function, that I may be able to populate it the easy way. Am I doing this wrong? I have a feeling it's a JavaScript issue, as the function call doesn't even seem to happen. When I open the browser debugger, for example, there is no indication of whether or not it was called.
update:
Here is the what the html-source lists:
<script type="text/javascript">
function populateCategory(subCategories, id) {
var select = document.getElementById(id);
var opt = document.createElement("option");
opt.text = "--Please make a selection--";
for (i = 0; i < subCategories.length; i++) {
var opt = document.createElement("option");
opt.value = i;
opt.text = subCategories[i];
select.add(opt);
}
}
</script>
<form action=/index.php?option=com_adsmanager&task=write&Itemid=1 method="post" name="editForm">
<div id="page1">
<select id="categories" name="category" onmouseover="populateCategory(Array, categories)" >
</select>
</div>
</form>
subCategoriesIt is in your JS function.I have a feeling it's a JavaScript issue- if you have such a feeling, you have to poist here a JS code, not PHP code.