You need to sign in to do that
Don't have an account?
bela
can any one help regarding javascript in visualforce
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.
When you are using javascript you have which js you are referring
Ex
Use debugger to check values in the js function
Before running the page open browser developer tools using Ctrl+shift + i and see the values for "console.log('<<<<val'+val);" in the console tab.
Try this code and let me know
Thanks,
pRAMODH.
Thanks for the response,I didn't add any JS, According to my knowledge if we use simple javascript,no need to add JS right? correct me if I am wrong.
I have checked log.console as you said,for val parameter it is taking <<<<val------------one:two:search,i dont know why it is taking this.can you please help me to solve this.
thanks,
Mahanandeesh.