2
<apex:page controller="CurrencyCon" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        alert();
        var x=1111111111111;
        $('[id$=abc]').val(x);
        var y='{!a}';
        alert(y);
    });
</script>
<apex:pageBlock >
<apex:form > 
    <apex:inputHidden value="{!a}" id="abc"/>
</apex:form>
     <apex:pageBlockSection columns="1">
        <apex:outputText value="$ {0, number, ########,##,#0.00}">
            <apex:param value="{!a}" />
        </apex:outputText>
        <apex:outputText value="$ {0, number, ###,###,###,##0.00}" >
            <apex:param value="{!b}" />
        </apex:outputText>
        <apex:outputText value="${0, number, ###,###,###,##0.00}">
            <apex:param value="{!c}" />
        </apex:outputText>
    </apex:pageBlockSection>
</apex:pageBlock>

</apex:page>

a,b,c are declared in currencycon (controller). I want to change "a" value using jquery.

5

You can define actionFunction, it will invoke controller method, and pass parameter from javascript

    <apex:actionFunction name="jsFunction" action="{!apexMethod}" >
        <apex:param value="" name="paramName"/>
    </apex:actionFunction>


    public void apexMethod() {
        String yourValue = ApexPages.currentPage().getParameters().get('paramName');
    }

use this in javascript like this:

...
jsFunction('yourValue');
...
0

Using Javascript

<script>
        $(document).ready(function(){
            alert();
            var x=1111111111111;
            $('[id$=abc]').val(x);
            var y='{!a}';
            alert(y);
           document.getElementById('{!$Component.aId}').value='your value';
        });
    </script>

    <apex:outputText id="aId" value="$ {0, number, ########,##,#0.00}">
          <apex:param value="{!a}" />
    </apex:outputText>

Using Jquery

<script>
    $(document).ready(function(){
        alert();
        var x=1111111111111;
        $('[id$=abc]').val(x);
        var y='{!a}';
        alert(y);
        $( 'span[id$=aId]' ).val('your value');
    });
</script>
  • Thanks for your response,my requirement is before it is printing into outputText I need to change that , I have to print that into outputText. – manoj Dec 4 '15 at 12:29
  • 1
    so make that that outputtext display:none then document.getElementById('{!$Component.aId}').value='your value'; after this link just make your outputtext display:block – Ratan Paul Dec 4 '15 at 12:32
  • @manoj Can you add more info in your question? – Ratan Paul Dec 4 '15 at 13:31
  • 2
    Thanks Rathan for your response.I got the reason why new value is not saving in "a".The reason is we are trying to assign the value using jQuery/js .But that value is in input hidden tag.It is not reaching the back-end.In output text we tried to print the value .Here that value is coming from back-end. Until we reload the page the new value won't be effect on "a".for that we need to write an action function and rerender that outputText portion. – manoj Dec 4 '15 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.