How can I set default text and value in jquery autocomplete and trigger select

I have an array of objects (assessorList), how can I set default text
and value in the jquery autocomplete and trigger select. For example if I
send second object from the array to the function then Assessor 2, Test
should be selected with 1116512 in AutoCompleteAssessorID and all the
statements under select should be executed for that selection.

My HTML:

My JavaScript:
var assessorList = [{ id=“1116542”, label=“Assessor 1,
Test”}, { id=“1116512”, label=“Assessor 2, Test”}, { id=“1117290”,
label=“Carey, Peter”}]

function a(ID, Text)
{
    $("#AutoCompleteAssessor").autocomplete({ 
    autoFocus: true, 
    minLength: 3,
    source: assessorList,
    focus: function(event, ui){ 
        $("#AutoCompleteAssessor").val(ui.item.label);
        $("#AutoCompleteAssessorID").val(ui.item.id);
        return false;
    },
    select: function(event, ui){                        
        $("#AutoCompleteAssessor").val(ui.item.label);
        $("#AutoCompleteAssessorID").val(ui.item.id);

        userId = ui.item.id;            
        getEventData();                 
        return false;
    },
    change: function (event, ui){
        if(!ui.item)
        { 
            $("#AutoCompleteAssessor").val('');
            $("#AutoCompleteAssessorID").val('');               
        }
    }
})  


}

First of all, those equal signs aren’t valid, and seem like they should be colons instead.

Second, can you please supply enough information so that we can rough up our own copy of your situation, so that we can test out possible solutions for you?

I have fixed the array:

var assessorList = [{ id:“1116542”, label:“Assessor 1, Test”}, { id:“1116512”, label:“Assessor 2, Test”}, { id:“1117290”, label:“Carey, Peter”}]

but I haven’t received any answers to my question(how can I set default text and value in jquery autocomplete and trigger select)

[quote=“asifakhtar, post:3, topic:205907, full:true”]but I haven’t received any answers to my question(how can I set default text and value in jquery autocomplete and trigger select)
[/quote]

For the purpose of exploring your coding problem, do you want us to create our own forms for use with testing?

Or do you think that it would be better for us to work with a relevant part of your own form?

To set the value can’t you run that code directly? If you’re wanting to share it then put that piece in

var selectItem = function(item) {
  $("#AutoCompleteAssessor").val(item.label);
  $("#AutoCompleteAssessorID").val(item.id);
    
  userId = item.id;
  getEventData();
}

...

select: function(event, ui){                        
  selectItem(ui.item);
  return false;
}

...

selectItem(assessorList[2]);

markbrown4 : thank you. I think this will work.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.