doulong2782 2014-04-25 05:32
浏览 33

如何通过jquery发送变量

I just created an autocomplete textbox via jquery now i am stuck with two problems.

1) I need to get the value of the selected item from the Autocomplete list.

So far i did these..

My jquery

$(document).ready(function(){
$("#tag").autocomplete("autocomplete.php", {
    selectFirst: true

});
});

I am getting the autocomplete list from the database its working fine, but the problem is that

2) When i type 'r' all the names with values gets populated and if i select say Robin from the list and try to display it with alert, i only gets 'r', (i only typed r,and selected 'robin' from list) why is this so?

here is the code i wrote for this

for the autocomplete textbox

  <input name="tags" type="text" id="tag"  value="" onchange= "newfn()" />

and in newfn()

<script>
        function newfn()
        {

             authname = document.getElementById("tag").value;

            document.autoquote.qid.value=authname;
            alert(authname);

        }
    </script>

and if i put an alert at first saying

alert("Hi");

then, i get first alert saying hi, and I get robin not r

So what is the correct way to get what value i selected from the autocomplete list?

Now my second Question is that the selected value from this autocomplete textbox, I need to pass it with another jquery to another php page so that I can get this value there and give it in a query as a criteria.

  • 写回答

4条回答 默认 最新

  • dt250827 2014-04-25 05:37
    关注

    you can use the autocomplete's select property like this

    $("#tag").autocomplete('autocomplete.php', {
        selectFirst: true,
        select: function (event, ui) {
            var label = ui.item.label;
            var value = ui.item.value;
            alert(label);
            alert(value)
         // you can write additional javascript code here to make use of these values
    
        }
     });
    

    Please check the jQuery UI documentation for more examples and info.

    Here is a JSFiddle.(Please note that an additional source attribute has been added in the fiddle to simulate the loading of data set as real cross domain AJAX calls are not allowed)

    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私