You need to sign in to do that
Don't have an account?
bela
need help regarding javascript in salesforce
Hi,
I wrote search functionality,In that i want to display no records found if a user gives value that have no records,this i want to display using javascript.not by pagemessages in controller.Below is the code.Please help me as I am new to java script.
VF:
---------------
<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(val){
var inputValue = document.getElementById(val).value;
<!--var inputValue = document.getElementById('one:two:search').value;-->
if(inputValue.length <= 0){
alert('no records found');
}
else{
actionFunName(inputValue);
}
}
</script>
<apex:pageMessages />
<apex:form id="two">
<apex:actionFunction name="actionFunName" action="{!searchpositions}" reRender="two" />
<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold" />
<apex:inputText value="{!search}" id="search" onkeyup="js('{!$Component.search}')" />
<!--<apex:inputText value="{!search}" id="search" />-->
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="two"/>-->
<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!poslis}" var="pl" >
<apex:column value="{!pl.name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!blockOnEnter}" >
<apex:pageBlockSection id="d">
<apex:pageBlockTable value="{!pos}" var="p" >
<apex:column value="{!p.name}"/>
<apex:column >
<apex:inputCheckbox value="{!p.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
-------------
public with sharing class searchwithactionstatuscontroller {
public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}
public PageReference searchpositions() {
string holdString ='SELECT name from Position__c where name like \'%'+search+'%\' ORDER BY name asc';
pos=Database.query(holdString);
blockOnLoad=false;
blockOnEnter=true;
return null;
}
public String search { get; set; }
public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}
public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}
}
Thanks,
Mahanandeesh.
I wrote search functionality,In that i want to display no records found if a user gives value that have no records,this i want to display using javascript.not by pagemessages in controller.Below is the code.Please help me as I am new to java script.
VF:
---------------
<apex:page controller="searchwithactionstatuscontroller" id="one">
<script>
function js(val){
var inputValue = document.getElementById(val).value;
<!--var inputValue = document.getElementById('one:two:search').value;-->
if(inputValue.length <= 0){
alert('no records found');
}
else{
actionFunName(inputValue);
}
}
</script>
<apex:pageMessages />
<apex:form id="two">
<apex:actionFunction name="actionFunName" action="{!searchpositions}" reRender="two" />
<apex:outputLabel for="search" value="SEARCH :" style="font-weight:bold" />
<apex:inputText value="{!search}" id="search" onkeyup="js('{!$Component.search}')" />
<!--<apex:inputText value="{!search}" id="search" />-->
<!--<apex:actionSupport event="onkeyup" action="{!searchpositions}" reRender="two"/>-->
<apex:pageBlock rendered="{!blockOnLoad}" id="block1">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!poslis}" var="pl" >
<apex:column value="{!pl.name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock rendered="{!blockOnEnter}" >
<apex:pageBlockSection id="d">
<apex:pageBlockTable value="{!pos}" var="p" >
<apex:column value="{!p.name}"/>
<apex:column >
<apex:inputCheckbox value="{!p.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
-------------
public with sharing class searchwithactionstatuscontroller {
public String error { get; set; }
public boolean blockOnLoad{set;get;}
public boolean blockOnEnter{set;get;}
public PageReference searchpositions() {
string holdString ='SELECT name from Position__c where name like \'%'+search+'%\' ORDER BY name asc';
pos=Database.query(holdString);
blockOnLoad=false;
blockOnEnter=true;
return null;
}
public String search { get; set; }
public List<position__c> poslis{set;get;}
public List<position__c> pos{set;get;}
public searchwithactionstatuscontroller() {
poslis=[select Name from position__c];
blockOnLoad=true;
blockOnEnter=false;
}
}
Thanks,
Mahanandeesh.