1

以下のスクリプトをフォームで使用します。国名でxmlドキュメントからコンテンツを取得し、gena​​meIdを隠しファイルに入れる必要があります。オートコンプリート検索は正常に機能します。問題は geonameId を隠しフィールドに入れる方法ですか?

JavaScript :

<script type='text/javascript'> 
$(window).load(function(){

$.ajax({
 type: "GET",
 url: "Region.xml", // change to full path of file on server
 dataType: "xml",

success: function(xmlResponse) {
        var data = $("geoname", xmlResponse).map(function() {
            return {
                value: $("Name", this).text() ,
                id: $("geonameId", this).text()
            };
        }).get();
        $("#test").autocomplete({
            source: function(req, response) {
                var re = $.ui.autocomplete.escapeRegex(req.term);
                var matcher = new RegExp("^" + re, "i");
                response($.grep(data, function(item) {
                    return matcher.test(item.value);
                }));
            },
            minLength: 2,
            select: function(event, ui) {
                $("#result").html(ui.item ? ui.item.id : "Nothing selected, input was " + this.value);
            }
        });
    }
});
}); 

</script>

html:

<div class="ui-widget">

    <input id="test" />
</div>

<input type="hidden" name="result" value="">

結果を非表示フィールドに入れる方法は?

4

1 に答える 1