【问题标题】:Using text field value in SQL query without it being submitted在 SQL 查询中使用文本字段值而不提交它
【发布时间】:2012-12-12 17:14:41
【问题描述】:

我正在使用 Oracle Application Express (Apex),基本上我的情况是:我有 2 个项目,一个是文本字段,另一个是隐藏项目,其值是通过使用 DB 链接查询表来检索的。

应该发生的情况是用户在文本字段中输入一个数字,然后在查询隐藏项时使用该数字来查找 ID 与用户输入的数字匹配的行。然后将隐藏项的值设置为该行的其中一列的内容。

唯一的问题是,这一切都在一个页面上,必须在不提交页面的情况下完成,所以当用户在文本字段中输入数字时,我如何将该数字存储为该项目的值,以便它可以在查询中用于计算隐藏项的值?

任何帮助将不胜感激。

【问题讨论】:

  • 什么版本的 Apex?动态操作可以在 Apex 4.0 及更高版本中执行此操作。
  • @JeffreyKemp Apex 4.2,我会看看动态动作,如果你知道我如何使用动态动作来做到这一点,请告诉我,谢谢
  • 您创建了一个动态操作,该操作在文本字段项上的 Change 事件上触发。 True 操作是一个 PL/SQL 块,它可以检索隐藏项的值。

标签: javascript sql oracle oracle-apex


【解决方案1】:

更新:

<!DOCTYPE html>
<html>
    <head>
        <script>
            function ajax(user_number) {
                var xmlhttp;
                // get the ID field for easy access... 
                var index =  document.getElementById("index");
                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                } else {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function() {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        // here you get back a response... xmlhttp.responseText
                        // set the hidden field with new data.
                        index.value = xmlhttp.responseText;
                    }
                }
                // here you make a request to your script to check your database...
                xmlhttp.open("GET", "app/search/?number=" + user_number + '&index=' + index.value, true);
                xmlhttp.send();
            }

            function check(user_number) {
                // make some validation here...
                if (user_number.length > 3) {
                    ajax(user_number);
                } else {
                    return;
                }
            }
        </script>
    </head>
    <body>

        <p>please enter your secret number</p>
        <!-- the hidden field holding the ID -->
        <input type="hidden" id="index" name="index" value="334" />
        <!-- the search text box where user type his own NUMBER onkeyup it make a request -->
        <input type="text" id="user-number" name="user-number" onkeyup="check(this.value);"/>

    </body>
</html>

【讨论】:

    猜你喜欢
    • 2014-09-19
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多