You need to sign in to do that
Don't have an account?
Ap30
Javascript validation not working in visualforce page
In my below code, only name validation is working fine. When amount is blank,send button is not disabled.I could able to send email.
Also when city and country is not entered, Click Me button is not hidden. I'm new to javascript. Please guide me.
======================================
<apex:page controller="Bookings" id="page">
<script>
function nameValidation(){
var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
if(n.value == "")
{
alert("Name is mandatory");
return false;
}
else{
return true;
}
}
function amtValidation(){
var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
if(at.value == "")
{
document.getElementById('{!$Component.page.form.pb.op.email}').disabled = true;
}
else
{
send();
}
}
function clickMe()
{
var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
if(a.value == "" )
{
document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
return false;
}
else if(b.value == "")
{
document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
return false;
}
else
{
return true;
}
}
</script>
<apex:form id="form">
<apex:actionFunction action="{!send}" name="send" reRender="pb" />
<apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
<apex:pageBlock title="Vendor Registration Form" id="pb">
<apex:pageBlockSection columns="2" id="pbs">
Name :<apex:inputText value="{!vcperson}" id="name"/>
Amount :<apex:inputText value="{!apevent}" id="amt"/>
City :<apex:inputText value="{!city}" id="city"/>
Country :<apex:inputText value="{!country}" id="coun"/>
</apex:pageBlockSection>
<apex:outputPanel id="op">
<apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
<apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Also when city and country is not entered, Click Me button is not hidden. I'm new to javascript. Please guide me.
======================================
<apex:page controller="Bookings" id="page">
<script>
function nameValidation(){
var n = document.getElementById('{!$Component.page.form.pb.pbs.name}');
if(n.value == "")
{
alert("Name is mandatory");
return false;
}
else{
return true;
}
}
function amtValidation(){
var at = document.getElementById('{!$Component.page.form.pb.pbs.amt}');
if(at.value == "")
{
document.getElementById('{!$Component.page.form.pb.op.email}').disabled = true;
}
else
{
send();
}
}
function clickMe()
{
var a = document.getElementById('{!$Component.page.form.pb.pbs.city}');
var b = document.getElementById('{!$Component.page.form.pb.pbs.coun}');
if(a.value == "" )
{
document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
return false;
}
else if(b.value == "")
{
document.getElementById('{!$Component.page.form.pb.op.pdf}').style.visibility="hidden";
return false;
}
else
{
return true;
}
}
</script>
<apex:form id="form">
<apex:actionFunction action="{!send}" name="send" reRender="pb" />
<apex:actionFunction action="{!clickme}" name="clickme" reRender="pb"/>
<apex:pageBlock title="Vendor Registration Form" id="pb">
<apex:pageBlockSection columns="2" id="pbs">
Name :<apex:inputText value="{!vcperson}" id="name"/>
Amount :<apex:inputText value="{!apevent}" id="amt"/>
City :<apex:inputText value="{!city}" id="city"/>
Country :<apex:inputText value="{!country}" id="coun"/>
</apex:pageBlockSection>
<apex:outputPanel id="op">
<apex:commandButton value="Send" id="email" action="{!send}" onclick="return nameValidation();return amtValidation()"/>
<apex:commandButton value="Click Me" id="pdf" action="{!clickme}" onclick="return nameValidation();return clickMe()"/>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Can you try the approach mentioned in https://salesforce.stackexchange.com/questions/97504/disabling-custom-javascript-button to hide the button
If this information helps, please mark the answer as best. Thank you