+ Start a Discussion
krishna chaitanya 35krishna chaitanya 35 

Javascript remoting to display a list of records in a pageblock or pageblock table

Hi ,
I tried to display list of accounts with searched name in the pageblock in visualforce using javascipt remoting.In the soql i am getting all the records but unable to display in the vf.Can anyone solve this puzzle.

<apex:page controller="AccountRemoter">
<script type="text/javascript">
function getRemoteAccount() {
    var accountName = document.getElementById('acctSearch').value;

        function(result, event){
            if (event.status) {
                // Get DOM IDs for HTML and Visualforce elements like this
                document.getElementById('remoteAcctId').innerHTML = result[i].Id
                    ).innerHTML = result[i].NumberOfEmployees;
                    ).innerHTML = result[i].Name;
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML =
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
         {escape: true}

    <input id="acctSearch" type="text"/>
    <button onclick="getRemoteAccount()">Fetch Accounts</button>
    <div id="responseErrors"></div>

    <apex:pageBlock id="block">
    <apex:pageBlockSection id="blockSection" columns="3">
        <apex:pageBlockSectionItem id="firstItem">
            <span id="remoteAcctId"/>
        <apex:pageBlockSectionItem id="thirdItem">
            <apex:outputText id="nameofacct"/>
        <apex:pageBlockSectionItem id="secondItem">
            <apex:outputText id="acctNumEmployees"/>

global with sharing class AccountRemoter {

public String accountName { get; set; }
public Account account { get; set; }
public AccountRemoter() {


global static List<Account> getAccount(String accountName) {

string strLikeString = '%'+accountName+'%';
        string strSOQL = 'select id,Name,NumberofEmployees from Account where name LIKE: strLikeString order by Name asc';
        List<Account> account = database.query(strSOQL);
return account;
krishna chaitanya 35krishna chaitanya 35
User-added image