PHP / AJAX - 填充的基础上选择列表3文本框与动态数据基础上、文本框、动态、数据

2023-09-10 15:49:37 作者:怀揣少女心

我试着去找到一个教程或东西,让我根据什么在选择下拉框中单击从一个MySQL数据库填充3文本框与数据。

例如,我的选择如下所示:

 <选择名称=imaselect>
    <期权价值=USA>美国< /选项>
    <期权价值=AUS>澳大利亚< /选项>
    <期权价值=NZ>新西兰< /选项>
< /选择>
 

然后在我有3个空白文本框。

为什么我的ajax不能获取文本框的值 下面有详细代码

如果我点击美国,就会去到数据库中,要求3个值,回报他们,然后把他们在3文本框,相同的,如果我点击AUS和相同的,如果我点击NZ。

任何帮助将是很大的AP preciated,即时通讯有这个麻烦了。

干杯,

解决方案

 <脚本类型=文/ JavaScript的>
    jQuery的(功能($){
        $(选择)。改变(功能(E){
            $(TEMP)。载荷(\'的index.php?参数1 = \'+ $(本).VAL(),()的函数{
                $(TextBox1的。)VAL($(temp1中。)文本()。)。
            });
        });
    });
< / SCRIPT>
 

这样的事情。当然,你必须设置一个引用了jQuery文件。然后你有一个的index.php(或命名不同),可以给它的参数,但是你通过下载功能需要。带班温度的元素将获得的内容,因为你不能使用负载直接获取数据在文本框中。 (所以你需要创建一个元素..隐藏的!)然后它被复制与类TextBox1的元素。复制2内侧线多次,只要你想(只使用像TextBox2中代替,温度可以保持不变)

Im trying to find a tutorial or something that will allow me to populate 3 textboxes with data from a mysql database based on whats clicked on in a select dropdown box.

For example, my select looks like the following:

<select name="imaselect">
    <option value="USA">USA</option>
    <option value="AUS">AUS</option>
    <option value="NZ">NZ</option>
</select>

Then under that i have 3 blank textboxes.

If i click USA, it will go to the database, ask for 3 values, return them and then put them in the 3 text boxes, same if i click AUS and the same if i click NZ.

Any help would be greatly appreciated, im having trouble with this.

Cheers,

解决方案

<script type="text/javascript">
    jQuery(function( $ ){    
        $("select").change(function(e) {    
            $(".temp").load(\'index.php?parameter1=\'+ $(this).val(), , function() {
                $(".textbox1").val($(".temp1").text());
            });
        });
    });
</script>

Something like this. Of course you have to set a reference to the jquery file. And then you have an index.php (or name it different) and can give it parameters however you want via the load function. The element with the class temp will get the content, because you cant use the load to get data in the textbox directly. (So you need to create that element .. hidden!) Then it gets copied into the element with the class textbox1. copy the 2 inner lines as many times as you want (just use like textbox2 instead, temp can stay the same)