You need to sign in to do that
Don't have an account?
Ap30
return false is not working in javascript
Hi All,
In my below code, return false is not working. I have highlighted those lines. Though i'm getting alert message "Enter state...." , command button is executed. Any help is appreciated.
=============
<apex:page controller="Bookings" id="page">
<script>
function nameValidation(id){
var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
if(n.value == "")
{
alert("Name is mandatory");
return false;
}
if(id == 'page:form:pb:pdf'){
this.clickMe();
}
}
function clickMe()
{
var a = document.getElementById('{!$Component.page.form.pb.pbs.state}');
var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
var pdfbtn = document.querySelector("[id$='pdf']");
if(a.value == "" )
{
alert("Enter state to show Generate Pdf Button");
pdfbtn.style.visibility = 'hidden';
return false;
}
else if(b.value == "")
{
alert("Enter Country to show Generate Pdf Button");
pdfbtn.style.visibility = 'hidden';
return false;
}
else
{
alert("inside else");
clickme();
}
}
</script>
<apex:form id="form">
<apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
<apex:actionFunction name="toggleButton" reRender="op"/>
<apex:pageBlock title="Booking Form" id="pb">
<apex:pageBlockSection columns="2" id="pbs">
Name :<apex:inputText value="{!person}" id="name" />
State :<apex:inputText value="{!state}" id="state" onchange="toggleButton()"/>
Country :<apex:inputText value="{!country}" id="coun" onchange="toggleButton()"/>
</apex:pageBlockSection>
<apex:outputPanel id="op">
<apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation(this.id);"/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
In my below code, return false is not working. I have highlighted those lines. Though i'm getting alert message "Enter state...." , command button is executed. Any help is appreciated.
=============
<apex:page controller="Bookings" id="page">
<script>
function nameValidation(id){
var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
if(n.value == "")
{
alert("Name is mandatory");
return false;
}
if(id == 'page:form:pb:pdf'){
this.clickMe();
}
}
function clickMe()
{
var a = document.getElementById('{!$Component.page.form.pb.pbs.state}');
var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
var pdfbtn = document.querySelector("[id$='pdf']");
if(a.value == "" )
{
alert("Enter state to show Generate Pdf Button");
pdfbtn.style.visibility = 'hidden';
return false;
}
else if(b.value == "")
{
alert("Enter Country to show Generate Pdf Button");
pdfbtn.style.visibility = 'hidden';
return false;
}
else
{
alert("inside else");
clickme();
}
}
</script>
<apex:form id="form">
<apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
<apex:actionFunction name="toggleButton" reRender="op"/>
<apex:pageBlock title="Booking Form" id="pb">
<apex:pageBlockSection columns="2" id="pbs">
Name :<apex:inputText value="{!person}" id="name" />
State :<apex:inputText value="{!state}" id="state" onchange="toggleButton()"/>
Country :<apex:inputText value="{!country}" id="coun" onchange="toggleButton()"/>
</apex:pageBlockSection>
<apex:outputPanel id="op">
<apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation(this.id);"/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Why you are returing false in JS? Is it to avoid the apex method call on button click.
If you want to avoid the method calling from button click simply put the false like below, and also remove the action from button.
Remove all the return false in JS.
Thanks,
Maharajan.C
All Answers
Why you are returing false in JS? Is it to avoid the apex method call on button click.
If you want to avoid the method calling from button click simply put the false like below, and also remove the action from button.
Remove all the return false in JS.
Thanks,
Maharajan.C
did you find a solution to disable the save button and generate a pdf for the vendor registration Visual force page?
if found can you share your code it will be so helpful for me to solve the problem.