【问题标题】:PHP / JS Change values of form dropdown with previous answer with databasePHP / JS 使用数据库的先前答案更改表单下拉列表的值
【发布时间】:2018-04-18 08:27:24
【问题描述】:

我正在尝试用数据库中的项目填充表单中的下拉框。 但它只需要填充与前一个输入字段相同的数据库中的数据。

假设我有一个看起来像这样的数据库:

我的 from 看起来像这样:

    <body>
        <form>
            <input id="nummer">
            <span></span>
        	<select name="name">
        		<option>name</option>
        	</select>
        </form>


    </body>

我已经找到了一种用这个 js 代码填充下拉框的方法,但这没有数据库:

$(document).ready(function()
        {
            $nummer = $("select[name='nummer']");
            $name = $("select[name='name']");

            $input = $(this).val();

            $('#nummer').bind('input', function()


                $(this).next().stop(true, true).fadeIn(0).html('[input event fired!]: ' + $(this).val());
                if ($(this).val() == "123")
                {
                    $("select[name='categorie'] option").remove(); 
                    $("<option>Pieter</option>").appendTo($categorie); 
                    $("<option>Steven</option>").appendTo($name); 
                }


            });


        });

当我在 number 输入字段中输入 123 时,我需要用 peter and steven

填充下拉框

这可能吗?

【问题讨论】:

  • ...你已经做了什么?
  • 是的,有可能。
  • 是的。你为什么不向我们展示你已经做了什么?
  • 我已经添加了我现在拥有的 js 我现在不知道如何继续@RomeoSierra
  • inside bind 对您的 php 脚本进行 ajax 调用(最好使用 debounce),该脚本会在数据库中查询匹配的 id 并将数据(名称)作为 json 返回。然后用该数据填充选择。

标签: javascript php jquery mysql sql


【解决方案1】:

对输入字段的onblur 事件进行编程以查找具有匹配值的下拉项。如果找到,将找到的下拉值标记为selected

$(document).ready(function(){
    $(document).on('#inputfield', 'blur', function(){
        $.ajax(
             //Properties
             //Current value of the input field should be sent to the server
             data:{inputValue:$('#inputfield').val()}, //Use this in where clause in the server
             success:function(){
                 // Populate the data into the dropdown
             }
        ); 
    }
})

这里我已经概述了你需要做的事情。

如果我填写其余部分,那将是我为你编程。而且我也没有必要的信息来填写其余的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多