简体   繁体   English

如何使用不带按钮和JavaScript的选择框来加载数据库内容

[英]How to load database content using Select box without button & javaScript

I'm making an administrative page for a website, for editing front-end contents. 我正在为网站制作一个管理页面,用于编辑前端内容。 I don't want to use JavaScript, I want to make it with raw PHP. 我不想使用JavaScript,而是要使用原始PHP。

The thing is: The user will choose a page from the select box, and the contents according to the page will be loaded into two text boxes. 问题是:用户将从选择框中选择一个页面,并将根据该页面的内容加载到两个文本框中。 Then the user will edit them on text boxes and update the contents using an update button. 然后,用户将在文本框中编辑它们,并使用更新按钮更新内容。

(there is no submit button for the select box, I want 'onselect' data content load) (没有用于选择框的提交按钮,我希望“ onselect”数据内容加载)

I need, the user will simply select a page, no button to be pressed then and the content will be loaded. 我需要,用户只需选择一个页面,然后不按任何按钮即可加载内容。 I want not to deploy JavaScript for this. 我不想为此部署JavaScript。 Is it possible using raw PHP? 是否可以使用原始PHP? Any suggestion? 有什么建议吗?

If you accept your users may have to use the enter key, which will submit the form, you're fine. 如果您接受您的用户,则可能必须使用Enter键,它将提交表单,您就可以了。

But you can't have an action occurring on a select, without even using the enter key, without javascript. 但是,即使没有使用Enter键,也没有javascript,就无法对select进行任何操作。

Note that the requirement to not use javascript, especially for an administrative tool, doesn't make sense. 请注意,不要使用javascript的要求(尤其是对于管理工具)是没有道理的。

PHP is a server side programming language. PHP是服务器端编程语言。 You can't really affect the client side directly, only indirectly through forms etc. 您不能真正地直接影响客户端,而只能通过表单等间接影响。

Yes, it's possible with raw PHP, but I do not recommend it. 是的,原始PHP可以实现,但我不建议这样做。

You can put the select-box inside a 您可以将选择框放在

<form action="targetFile.php" method="GET">

To submit the form without a submit-button, you can use: 要提交没有提交按钮的表单,可以使用:

<select name="sel" onChange="this.form.submit()">

When the form is submitted, the browser loads the site "targetFile.php" On this site, you can use php to set the text-box content: 提交表单后,浏览器将加载网站“ targetFile.php”。在此网站上,您可以使用php设置文本框内容:

<input type="text" value="
    <?php
        if($_GET['sel'] == 0) echo "content1";
        else echo "content2";
    ?>
">

If you want to load the content dynamically (without realoading a site) you have to use Javascript and maybe Ajax. 如果要动态加载内容(不重新加载站点),则必须使用Javascript,也许还需要使用Ajax。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM