开发者

jQuery multiple form inputs and multiple sources

I have 2 separate form fields where I would like to utilize jQuery's autocomplete function. Currently I have 2 separate functions defined as well as 2 different identifiers for the input for fields. Currently only one works. Here is what my code looks like

form.cfm

<script type="text/javascript">
$(function() {
    $("#name").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "cfc/cfc_auto1.cfc?method=getCustomerNames&returnformat=json",
                dataType: "json",
                data: {
                    nameCustomerSearchString: request.term,
                    nameid: request.term,
                    Comp: $('#Comp').val(),
                    maxRows: 25
                },

                success: function(data) {
                    response(data);
                }
            });
        }
    });
});
</script>

<script type="text/javascript">
$(function() {
    $("#name2").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "cfc/cfc_auto2.cfc?method=getNames&returnformat=json",
                dataType: "json",
                data: {
                    nameSearchString: request.term,
                    nameid: request.term,
                    Comp: $('#Comp').val(),
                    maxRows: 25
                },

                success: function(data) {
                    response(data);
                }
            });
        }
    });
});

<form...
<input id="Name" name="Contact" value="" size="70" />
.../form>

<form...
<input id="Name2" name="Contact" value="" size="70" />
.../form>

I can show the cfc's but they both 开发者_如何学JAVAwork when used by themselves. They are identical except for the query. Auto1.cfc queries a different table then Auto2.cfc.


From what I see the name attribute of the input fields is different from their id attribute.

Also the two input fields share the same name attribute. Try doing:

<form name="form1" id="form1">
    <input id="Contact1" name="Contact1" value="" size="70" />
    ...
</form>

<form name="form2" id="form2">
    <input id="Contact2" name="Contact2" value="" size="70" />
    ...
</form>

I think it was trying to get the wrong fields.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜