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:

它在select标签上使用以下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);
    }
}

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.

我发布的最后一个函数向数据库发出请求,获取用于创建下拉列表的类别列表。我认为,如果我将获得的类别传递给JavaScript函数,我可以轻松地填充它。我做错了吗?我觉得这是一个JavaScript问题,因为函数调用似乎甚至没有发生。例如,当我打开浏览器调试器时,没有迹象表明它是否被调用。

update:

更新:

Here is the what the html-source lists:

这是html源列出的内容:

<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&amp;task=write&amp;Itemid=1 method="post" name="editForm">

    <div id="page1">

        <select id="categories" name="category" onmouseover="populateCategory(Array, categories)" >

        </select>

    </div>

</form>

1 个解决方案

#1


2

I't not a javascript issue but rather understanding issue.

我不是一个javascript问题,而是理解问题。

which calls the following function <- here is your mistake.

它调用以下函数< - 这是你的错误。

JS cannot call PHP functions. As it's run in the browser, while PHP being run on the server, a thousand miles away.
Quite contrary, its indeed PHP creates all the JS along with HTML and stuff.

JS无法调用PHP函数。因为它在浏览器中运行,而PHP在服务器上运行,距离千里之外。相反,它确实PHP创建了所有的JS以及HTML和东西。

So, your PHP code have to create the JS function call already populated with data.
Have you checked the HTML source? Does it contain proper JS function call?

因此,您的PHP代码必须创建已填充数据的JS函数调用。你检查过HTML源代码吗?它是否包含正确的JS函数调用?

Update See, as soon as you posted the actual JS, it become as simple as an egg

更新看到,一旦你发布了实际的JS,它变得像鸡蛋一样简单

<select id="categories" name="category" onmouseover="populateCategory(Array, categories)" >

it says just "Array" instead of actual data.
Means you are trying to print an array as a strings. Which obviously won't work.
Use some loop to iterate that array and print it's contents in the appropriate (for JS) format.

它只是说“数组”而不是实际数据。意味着您尝试将数组作为字符串打印。这显然是行不通的。使用一些循环来迭代该数组并以适当的(for JS)格式打印它的内容。

更多相关文章

  1. mysql利用st_distance函数查询附近的点的功能
  2. MySQL按数组值排序
  3. mySql中SUBSTRING_INDEX函数用法
  4. 向数组添加一组数据库列的问题
  5. 在H2数据库中插入时间——函数“PARSEDATETIME”未找到
  6. MySQL 运算符和函数
  7. 如何使用webrequest使用Json数组绘制折线图
  8. 使用QSqlDatabase类的open函数导致程序崩溃
  9. 如何在php imap函数中看到看不见的电子邮件

随机推荐

  1. PHP XAMPP配置PHP环境和Apache80端口被占
  2. 【PHP面向对象(OOP)编程入门教程】15.sta
  3. 看见有人发帖“php能做什么”,我不得不也
  4. Laravel Auth只验证管理员/超级用户
  5. 如何用PHP和MYSQL在逗号分隔的列表中找到
  6. phpStudy 2016 更新下载,新版支持php7.0
  7. 2016.5.27 php测试中敏感度高,怎么调整
  8. jsonencode添加一个空行,为什么?
  9. 如何将java中的值添加到php中?
  10. Validate PEAR包是否可以投入生产?