开发者

how to get value of autosuggest plugin

I am using this http://code.drewwilson.com/entry/autosuggest-jquery-plugin

Here is my html

   <h1>Category : </h1>
    &nbsp;<input type="text" name="category" id="category" size="4"/> 
    &nbsp;<input type="button" name="category" id="gocategory"  value="Go"/>

here is my jquery code :

$(document).ready(function() {
  // put all your jQuery goodness in here.
    var data = {items: [
        {value: "21", name: "Mick Jagger"},
        {value: "43", name: "Johnny Storm"},
        {value: "46", name: "Richard Hatch"},
        {value: "54", name: "Kelly Slater"},
        {value: "55", name: "Rudy Hamilton"},
        {value: "79", name: "Michael Jordan"}
    ]};
    $("#category").autoSuggest(data.items, {s开发者_运维技巧electedItemProp: "name", searchObjProps: "name"});
    // $("#category").autoSuggest("http://mysite.com/path/to/script", {minChars: 2, matchCase: true});;
    $("#gocategory").click(function(){
        alert($("#category").value);
    });
});

How i will get the value of the selected category in the onclick event ?


with option

asHtmlID:"rech"

(rech is a sample name) the value save in it with comma seperator and it's be hidden field which can get value with

$("input[name='as_values_rech']").val()

if dont set "asHtmlID" ... , autoSuggest give a random name for it, and in your code:

$("#category").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name" ,
selectedValuesProp:"value",asHtmlID:"rech"});

$("#gocategory").click(function(){
        alert($("input[name='as_values_rech']").val());
    });


Maybe using .val() will do the trick. I'm not familiar with this plugin thou.

alert($("#category").val());


There is an event onsubmit or something like tis on each selection that function is executed .so by that way we can get the value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜