You need to sign in to do that
Don't have an account?
Sanchivan Sivadasan
inputText prevent postback if less than 2 characters
Hi there,
I have an inputText field and a button as follows:
<apex:inputText onkeyup="enableDisableGoButton(event);" onkeypress="searchTextEnterPostBack(event);" value="{!searchstring}" id="theSearchstring" maxlength="100" size="50" /> <apex:commandButton value="Go" id="submitButton" styleClass="goButtonDisabled" reRender="theSearchResults" />
Here are the Java Script Functions:
function enableDisableGoButton(event) { var seachInputText = document.getElementById("{!$Component.theSearchstring}"); var goButton = document.getElementById("{!$Component.submitButton}"); if(seachInputText.value.length < 2) { goButton.className = "goButtonDisabled"; } else { goButton.className = "goButtonEnabled"; } } function searchTextEnterPostBack(event) { var keynum = 0; if (window.event) { keynum = window.event.keyCode; } else if (e.which) { keynum = e.which; } if (keynum == 13) { if(seachInputText.value.length < 2) { return null; } else { return true; } } }
So far I have the Go button hide when there is less than two characters on the inputText. That works fine. But when the user clicks enter it does a post back. I want to check if the user pressed enter and if the inputText has less than 2 characters then I don't want the post back to happen if it has atleast 2 characters then the post back should happen as normal.
I am using what is in the inputText as the keyword for <knowledge:articleList>.
Please help. Thanks.
try this
Hi Big V,
I tried that and it still posts back. Do you have any other suggestions? Thanks.