<apex:inputText id="searchBar" value="{!nameSearch}"/>
<apex:commandButton value="Search" action="{!search}" rerender="Everything" status="statusId" onclick="if({!nameSearch}.length() < 3){alert('Please enter at least 3 characters to search.');return};"/>
I am trying to make a search bar that only does the search if at least 3 characters are entered. I am having trouble with it actually executing the onclick statement though. The idea is that when I click search it checks to make sure that the variable nameSearch has at least 3 characters, if it does then it goes on to the action attribute to execute the search method and if not then it does an alert box and does not execute the search method.
The way it is now, I search for 'Ro' and it doesn't seem to do anything at all.