In the code below, I need to be able to use JS to call renderResults();
in my controller, only if a user clears the field where customerToClearSearchText
goes on the VF page.
If I remove the condition, the method successfully executes; so I know that's where the problem is.
<apex:outputpanel >
<apex:inputText id="customerToClearSearchText" value="{!customerToClearSearchText}" rendered="{!customerToClearInputRendered}" onkeydown="showResults()"/>
<apex:actionFunction name="CallApexMethod" action="{!renderResults}"/>
<script>
function showResults(){
var st = document.getElementById("customerToClearSearchText").value;
if(st.length == 0){
CallApexMethod();
}
}
</script>
</apex:outputpanel>
To no avail I also tried:
document.getElementById("customerToClearSearchText")
if(!st)
if(!!st)
My guess is it doesn't work because the condition is evaluating the (now) populated string - customerToClearSearchText
- in the controller; not the length of anything the user is (now) putting into the field on the page.
At any rate, is there anyway to do what I'm trying to accomplish? BTW, I'm completely new to JS.