function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Soujanya Uppal 9Soujanya Uppal 9 

Hi, i want to show whatever city i type on click on search button on vf page then through apex it shows that records belongs to that city on system.debug

Suraj Tripathi 47Suraj Tripathi 47

Hi Soujanya,

Please find the solution.

<apex:page Controller="searchBox">
    <apex:form >
        <apex:inputText value="{!searchKey}" label="Input"/><br/>
        <apex:commandButton value="Enter" action="{!search}"/>
        <apex:pageBlock title="Searched Accounts are:-">
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
public class searchBox {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public searchBox( ) {} 
    public void search(){
        string searchquery='select Name,id from account where name like \ +searchKey+'%\'';
        acc= Database.query(searchquery);
system.debug(acc);
    }
}

Please mark it as the Best Answer so that other people can take references from it.

Thank You