You need to sign in to do that
Don't have an account?

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
<apex:page controller="AccountRemoter">
<script type="text/javascript">
function getRemoteAccount() {
var accountName = document.getElementById('acctSearch').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.AccountRemoter.getAccount}',
accountName,
function(result, event){
if (event.status) {
// Get DOM IDs for HTML and Visualforce elements like this
for(i=0;i<=result.length;i++){
document.getElementById('remoteAcctId').innerHTML = result[i].Id
document.getElementById(
"{!$Component.block.blockSection.secondItem.acctNumEmployees}"
).innerHTML = result[i].NumberOfEmployees;
document.getElementById(
"{!$Component.block.blockSection.thirdItem.nameofacct}"
).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}
);
}
</script>
<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>
<apex:pageBlockSectionItem id="thirdItem">
<apex:outputText id="nameofacct"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id="secondItem">
<apex:outputText id="acctNumEmployees"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
====class====
global with sharing class AccountRemoter {
public String accountName { get; set; }
public Account account { get; set; }
public AccountRemoter() {
}
@RemoteAction
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;
}
}
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
<apex:page controller="AccountRemoter">
<script type="text/javascript">
function getRemoteAccount() {
var accountName = document.getElementById('acctSearch').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.AccountRemoter.getAccount}',
accountName,
function(result, event){
if (event.status) {
// Get DOM IDs for HTML and Visualforce elements like this
for(i=0;i<=result.length;i++){
document.getElementById('remoteAcctId').innerHTML = result[i].Id
document.getElementById(
"{!$Component.block.blockSection.secondItem.acctNumEmployees}"
).innerHTML = result[i].NumberOfEmployees;
document.getElementById(
"{!$Component.block.blockSection.thirdItem.nameofacct}"
).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}
);
}
</script>
<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>
<apex:pageBlockSectionItem id="thirdItem">
<apex:outputText id="nameofacct"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id="secondItem">
<apex:outputText id="acctNumEmployees"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
====class====
global with sharing class AccountRemoter {
public String accountName { get; set; }
public Account account { get; set; }
public AccountRemoter() {
}
@RemoteAction
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;
}
}
