You need to sign in to do that
Don't have an account?
Javeed Shaik
Unable to call remote action method usging javascript in visualforce page
I wanted to display a case details as a table when user enters a case number and hit ''search" button.
I dont know what is wrong with my code. I also tried to display the searched element on browser console and log.. but its not working. Pleae help me out!!
My Controller:
and here is my Visualforce Page:
Thanks in Advance!!
Javeed Shaik
I dont know what is wrong with my code. I also tried to display the searched element on browser console and log.. but its not working. Pleae help me out!!
My Controller:
global with sharing class CaseSearch { public string searchElement {get; set;} public static Case c; public CaseSearch(ApexPages.StandardController controller) { } @RemoteAction global static Case caseSearchMethod(string searchElement){ c = [SELECT Id,Account.name,status FROM Case WHERE CaseNumber= :searchElement LIMIT 1]; system.debug(searchElement); return c; } }
and here is my Visualforce Page:
<apex:page standardController="Case" extensions="CaseSearch"> <apex:messages /> <style> input{ float: center; width: 100%; padding: 12px 50px; margin: 8px 0; display: inline-block; border: 2px solid #ccc; border-radius: 4px; box-sizing: border-box; } .center{ margin: auto; width: 60%; //border: 3px solid #73AD21; padding: 10px; } h{ font-size: 20px; text-align: center; } table { border: 1px solid; padding: 12px 20px; } </style> <script type="text/javascript"> function search(){ var searchElement = document.getElementById.('case_number').value; window.alert("Hello!"); console.log(searchElement); Visualforce.remoting.manager.invokeAction("{!$remoteAction.CaseSearch.caseSearchMethod}",searchElement,function(result,event){ if(event.status){ console.log(searchElement); } }); } </script> <br/><br/><br/><br/> <div class="center"> <input placeholder="Please Enter Your Case Number Here" id="case_number"></input> <Button type="button" value="Search" onclick="search()">Search</button> </div> <div id="caseDetails" class="center" rendered="false"> <table style="width:100%"> <tr> <th style="25%">Case Number</th> <th style="25%">Name</th> <th style="25%">Status</th> </tr> <tr> <td><apex:outputText value="{!C.CaseNumber}"></apex:outputText></td> <td><apex:outputText value="{!C.account.name}"></apex:outputText></td> <td><apex:outputText value="{!C.status}"></apex:outputText></td> </tr> </table> </div> </apex:page>*It would be nice if you help me to show the case details table only after I hit 'Search' button and align the search button to center.
Thanks in Advance!!
Javeed Shaik
There is a syntax error in search() method. Remove the dot after getElementById! And add result html in the callback method. Case number is also required in the query if you display it.
I also modified the visibility of the case details table :D
Controller:
Page:
All Answers
There is a syntax error in search() method. Remove the dot after getElementById! And add result html in the callback method. Case number is also required in the query if you display it.
I also modified the visibility of the case details table :D
Controller:
Page:
Thank you very much! it worked for me!! :)