A workaround for accessing Javascript values from Apex

<apex:page controller="javaScriptToApex" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<apex:form >
<input type="text" id="jsInputfld" onkeyup="j$('.vfInputField').val(j$(this).val());"/>
<apex:inputText style="display:none" styleClass="vfInputField" value="{!firstVal}"/>
<apex:commandButton value="Get Square Value of Input # from Controller" action="{!viaController}" reRender="op1" status="status"/>
</apex:form>
<apex:actionStatus startText="Processing..." id="status"></apex:actionStatus>
<apex:outputPanel id="op1">
<apex:outputText > {!firstVal}</apex:outputText>
</apex:outputPanel>
<script>
j$ = jQuery.noConflict();
//j$(".vfInputField").val('5');
</script>
</apex:page>

public class javaScriptToApex {

    public PageReference viaController() {
        firstVal = firstVal *firstVal ;
        return null;
    }

public Integer firstVal {get;set;}

}


http://sbox-developer-edition.ap2.force.com/javaScriptToApex

Comments

Popular posts