简体   繁体   English

Perl cgi-bin自动完成

[英]Perl cgi-bin auto complete

I have a very simple website that I built using Perl cgi-bin. 我有一个使用Perl cgi-bin构建的非常简单的网站。 I have one form field that displays all the application codes in my small company. 我有一个表单字段,显示我的小公司中的所有应用程序代码。 Since the application list was small, I used a simple drop down list. 由于应用程序列表很小,因此我使用了一个简单的下拉列表。 However, with growing number of applications, the drop down is turning out to be unmanageable. 但是,随着应用程序数量的增加,下拉列表变得难以管理。 Is it possible to use auto-complete for this field using Perl cgi ? 是否可以使用Perl cgi在此字段中使用自动完成功能?

Edit : The application names are stored in a database table. 编辑:应用程序名称存储在数据库表中。 I pull the application list from the database. 我从数据库中提取应用程序列表。

HTML5 has a nifty tag for Autocomplete Dropdown, <datalist> . HTML5具有一个用于自动完成下拉菜单的漂亮标签<datalist> Below is the usage definition for this tag as found on w3schools.com: 以下是在w3schools.com上找到的该标签的用法定义:

Definition and Usage The <datalist> tag specifies a list of pre-defined options for an <input> element. 定义和用法<datalist>标记为<input>元素指定预定义选项的列表。

The <datalist> tag is used to provide an "autocomplete" feature on elements. <datalist>标记用于在元素上提供“自动完成”功能。 Users will see a drop-down list of pre-defined options as they input data. 用户在输入数据时将看到一个预定义选项的下拉列表。

Use the <input> element's list attribute to bind it together with a <datalist> element. 使用<input>元素的list属性将其与<datalist>元素绑定在一起。

Code Example: 代码示例:

<input list="browsers">

<datalist id="browsers">
  <option value="Internet Explorer">
  <option value="Firefox">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
</datalist>

在此处输入图片说明

For more details, refer to this link: http://www.w3schools.com/tags/tag_datalist.asp 有关更多详细信息,请参见以下链接: http : //www.w3schools.com/tags/tag_datalist.asp

Alone Perl-CGI it can't do. 单独的Perl-CGI无法做到。

Try to use javascript inside your CGI script. 尝试在CGI脚本中使用javascript。 I added the sample html and javascript below 我在下面添加了示例html和javascript

HTML code HTML代码

<form>
    <input type="text" id="someid" onkeyup="myfunc()" style="width:150px"/>
        <div id='auto_div' style="position:absolute; width:150px; height:100px;">
        </div>
</form>

Javascript with AJAX call 带有AJAX调用的Javascript

function myfunc()
{
    var val = document.getElementById("someid").value;


    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var res = xmlhttp.responseText;         
            document.getElementById("auto_div").innerHTML= res;
        }   
    }

    xmlhttp.open("GET","database.pl?input_value="+val,true);
    xmlhttp.send();
}

Trigger the myfunc function on every keyup ( onkeyup() ) then get the value of input tag. 在每个keyup( onkeyup() )上触发myfunc函数,然后获取输入标签的值。 Then pass the value from the DB connecting perl file using ajax the result of the output will store into the res variable then write the conent into the auto_div 然后使用ajax从数据库连接的perl文件中传递值,输出结果将存储到res变量中,然后将内容写入auto_div

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache Perl cgi-bin设置:内部服务器错误 - Apache Perl cgi-bin setup: Internal Server Error 如何在perl cgi-bin脚本中使用utf-8? - how to use utf-8 in a perl cgi-bin script? Perl:获取在cgi-bin脚本中使用的stdin的句柄 - Perl: getting handle for stdin to be used in cgi-bin script Docker httpd apache 并让 cgi-bin 执行 perl 脚本 - Docker httpd apache and getting cgi-bin to execute perl script 如何允许perl cgi-bin脚本运行系统命令? - How to allow perl cgi-bin script to run system commands? Perl / CGI不适用于/ home / user / cgi,但适用于/ var / www / cgi-bin - Perl/CGI not working for /home/user/cgi but working for /var/www/cgi-bin 访问cgi-bin中的图像 - access an image in cgi-bin 如何在Ubuntu 10.04的“ root-directory / cgi-bin”中的“ root-directory / sub-directory / cgi-bin”中设置服务器以运行perl脚本? - How to set server to run the perl script in “root-directory/sub-directory/cgi-bin” from “root-directory/cgi-bin” in Ubuntu 10.04? 没有这样的文件或目录:&#39;/ opt / lampp / cgi-bin /的exec失败,PERL XAMPP Ubuntu - No such file or directory: exec of '/opt/lampp/cgi-bin/ failed PERL XAMPP Ubuntu 配置Apache2以允许客户端在cgi-bin中运行Perl脚本 - Configure Apache2 to allow clients to run Perl Scripts in cgi-bin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM