Whenever I am writing a javascript code to check if the input text is taking an empty value, it doesn't work. Please check what is the problem with my code?
Apex Page Code
<apex:page controller="sampleGetSet">
function checkValidation(){ var val1 = document.getElementsById('name').value; if(val1==null || val1==""){ alert('Please enter any value'); return true; } } <apex:form >
<apex:pageBlock >
<apex:outputText value="Enter your Name"></apex:outputText>
<apex:inputText id="name" value="{!inputtext}" required="true"/>
<apex:commandButton value="show" reRender="display" oncomplete="this.form.reset();" onclick="checkValidation()"/>
</apex:pageBlock>
</apex:form>
<apex:pageblock id="display">
The name entered is:
<apex:outputtext value="{!inputtext}"/>
</apex:pageblock>
</apex:page>
Apex Controller Code:Page Code
public class sampleGetSet
{
public string inputtext {get; set;}
}