Autocomplete not running on the third field

Discussion in 'jQuery' started by sarahk, Mar 4, 2014.

  1. #1
    I've got a couple of fields with autocomplete running on them and populating hidden fields - but on the third field, which is just a cut and paste of the second it doesn't even fire. For the first two I can "inspect" and look at the network tab and see my keystrokes being translated into ajax requests. The third - nothing happens, nothing in network, nothing in console.

    Any ideas?

    upload_2014-3-4_21-47-4.png

    <script type='text/javascript'> $(function() {
            $("#RegistrationTradingname").autocomplete({
                source: "/registrations/getTradingName",
                minLength: 2,
                select: function( event, ui ) {
                    if (ui.item){
                        $('#RegistrationMembershipId').val(ui.item.id);
    
                        console.log(ui.item.value);
                        console.log(ui.item.id);
                    }
             
                }
            });
    
            $("#RegistrationName1").autocomplete({
                minLength: 2,
                cacheLength: 0,
                source: function( request, response ) {
                    $.ajax({
                        url: "/registrations/getMemberName/",
                        dataType: "json",
                        data: {
                            membership_id: $('#RegistrationMembershipId').val(),
                            term: request.term
                        },
                        success: function(data) {
                            response(data);
                        }
                    });
                },
                select: function( event, ui ) {
                    if (ui.item){
                        var res = ui.item.value.split("|");
                        $('#RegistrationFirstname').val(res[0]);
                        $('#RegistrationName').val(res[1]);
                        ui.item.value = res[0]+' '+res[1];
                    }
                }
            });
    
            $("#RegistrationName2").autocomplete({
                minLength: 2,
                cacheLength: 0,
                source: function( request, response ) {
                    $.ajax({
                        url: "/registrations/getMemberName/",
                        dataType: "json",
                        data: {
                            membership_id: $('#RegistrationMembershipId').val(),
                            term: request.term
                        },
                        success: function(data) {
                            response(data);
                        }
                    });
                },
                select: function( event, ui ) {
                    if (ui.item){
                        var res = ui.item.value.split("|");
                        $('#RegistrationFirstname2').val(res[0]);
                        $('#RegistrationName2').val(res[1]);
                        ui.item.value = res[0]+' '+res[1];
                    }
                }
            });
    
        });
    </script>
    HTML:
     
    Solved! View solution.
    sarahk, Mar 4, 2014 IP
  2. #2
    Maybe a stupid question, but are there any typos in the field names/IDs for the third field in your HTML? The number of times I have copied and pasted HTML then either not amended a name/ID or made a typo...
     
    ryan_uk, Mar 4, 2014 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,808
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Oh, I know that one well, I don't think so...
     
    sarahk, Mar 4, 2014 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,808
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Ryan - you were right on the money and I didn't see it staring me in the face! Realised that my hidden field and my display name had the same id, didn't happen to the first because the display name had a 1 while the hidden fields didn't.
     
    sarahk, Mar 4, 2014 IP