You need to sign in to do that
Don't have an account?
prasanth puvvada 4
javascript textbox not validating if empty
senario:- in the textbox if i dont enter any data and click on submit then it say please enter name. This page is not showing any error. after executing the desired output is not coming. <apex:page id="page"> <script> function show() { var name=document.GetElementById('page:f1:p1:ip1').value; if(name="" || name=nulll) { document.GetElementBy.id('page:f1:p1:op2').innerHtml='please enter your name'; } </script> <apex:form id="f1"> <apex:pageblock id="p1"> <apex:outputlabel value="Enter u r name" id="op1" /> <apex:inputtext id="ip1" /> <apex:commandbutton value="submit" onclick="show();" /> <apex:outputlabel id="op2" /> </apex:pageblock> </apex:form> </apex:page>
NOTE: JavaScript is Case Sensitive. So be aware before starting javascript code.
I have modified your code, take a look on the below code. If the below solutions works for you, then please mark this as solution. :)
You can start your javascript basic at http://www.w3schools.com/js/
All Answers
NOTE: JavaScript is Case Sensitive. So be aware before starting javascript code.
I have modified your code, take a look on the below code. If the below solutions works for you, then please mark this as solution. :)
You can start your javascript basic at http://www.w3schools.com/js/
I have jquery. Please use the jquery file in static resource it will help later on also.
<apex:page id="page">
<script>
function show()
{
var name = $('.inputText').val();
if(name === "" || name === null)
{
$('.errorMsg').show();
}
else {
$('.errorMsg').hide();
}
</script>
<style>
.errorMsg {
display: none;
}
</style>
<apex:form id="f1">
<apex:pageblock id="p1">
<apex:outputlabel value="Enter u r name" id="op1" />
<apex:inputtext id="ip1" styleClass="inputText"/>
<apex:commandbutton value="submit" onclick="show();" />
<apex:outputlabel id="op2" styleClass="errorMsg" >
Please eneter your name
</apex:outputlabel>
</apex:pageblock>
</apex:form>
</apex:page>
Please let me know if it is helpfull..
Thanks
Sunil