I have a public site in LWC, which has input Fields.

In that i have search input field, this will fetch the Name from custom object( Basically I'm trying to achieve to do a custom look up).

Value is displaying below to the Input field based on the text which i entered, But When i select the any one of the result value It print's undefined.

On select the value, want to get the Id and display the Name in the field, Also want to clear the result set.

Below is my code, Can anyone Please guide me on this. Thanks in Advance.


 handleselectSchool(event) {
    // alert(event.currentTarget.dataset.Id);
    // alert(event.target.dataset.menuItemId); 

<div class="slds-size_1-of-2">
    <div class="slds-text-align_center slds-m-around_x-small">
        <lightning-input type="search" onchange={handleKeyChangeGetSchool}
            class="slds-m-bottom_small" value={schoolVal} label="School">
        <template if:true={schoolData}>
            <template for:each={schoolData} for:item="sc" for:index="index">
                <li class="slds-nav-vertical__item" key={sc.Id}
                    data-id={sc.Id} data-name={sc.Name}>

                    <a class="slds-nav-vertical__action"
                        onclick={handleselectSchool} aria-current="true">
                        <lightning-icon icon-name="standard:education"
                            alternative-text="skill" title="Account"
                        &nbsp; {sc.Name}
            <!-- <lightning-datatable key-field="Id" data={schoolData}
                    columns={schoolcolumns} hide-checkbox-column="true"
                </lightning-datatable> -->

1 Answer 1


You just need to put the attributes on the link itself:

<a class="slds-nav-vertical__action"
    data-id={sc.Id} data-name={sc.Name}
    onclick={handleselectSchool} aria-current="true">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.