Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:47:23+00:00 2026-06-07T16:47:23+00:00

My code is working fine, but I am really not able to clearly understand

  • 0

My code is working fine, but I am really not able to clearly understand it.

Can someone explain me please.

This is my code:

<script type="text/javascript">
    var portletNamespace = '#<portlet:namespace/>\\:formId\\:';
    $(portletNamespace + 'drpCategory').live('change', function () {
        alert('#{myController.simpleString}');
        $(portletNamespace + 'hiddenValue').ready(function () {
            alert($(portletNamespace + 'hiddenValue').val());
        });
    });
</script>

<h:inputText id="hiddenValue" value="#{myController.simpleString}" />

<h:selectOneMenu id="drpCategory">
    <f:selectItem itemLabel="Chọn thủ tục" itemValue="#{null}" />
    <f:selectItems value="#{myController.listCate}" var="item" itemLabel="#{item.cateNane}"
    itemValue="#{item.cateId}" />
    <f:ajax event="valueChange" render="hiddenMap " listener="#{myController.changeCategory}"
    />
</h:selectOneMenu>

after I change item in drpCategory, javascript alerts empty string first and then real value of simpleString. But if I remove the first alert code, the second will show me old value (before rendered by ajax)

For example, if I remove first alert code. First, hiddenValue is empty, change drpCategory value, hiddenValue changed to 'a' but javascript alert empty, second time when I change drpCategory then hiddenValue is changed to 'b' but it will still show 'a'.

edit:
ah, I find out something, I had changed to:

 <script type="text/javascript">
    var portletNamespace = '#<portlet:namespace/>\\:formId\\:';     
    $(portletNamespace+'drpCategory').live('change', function(){
        setTimeout('myFunc()', 500);    

    });

    function myFunc(){
            $(portletNamespace+'hiddenValue').ready(function(){
                alert($(portletNamespace+'hiddenValue').val());
            });
    }
   </script> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:47:26+00:00Added an answer on June 7, 2026 at 4:47 pm

    If I understood your scenario right..

    Change your

    <f:ajax event="valueChange" render="hiddenMap " listener="#{myController.changeCategory}"
    />
    

    into

    <f:ajax onevent="callThisMethodAfterValueIsUpdated" event="valueChange" render="hiddenMap " listener="#{myController.changeCategory}"
    />
    

    and in your js add this

    var portletNamespace = '#<portlet:namespace/>\\:formId\\:'; 
    function callThisMethodAfterValueIsUpdated(data) {
        if (data.status === 'success') {
            alert($(portletNamespace+'hiddenValue').val());
        }
    }
    

    relying on setTimeout is wrong cause it may vary from time to time server/traffic…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This line of code is working fine for Firefox $(#<%=txt1.ClientID%>).text() but not for IE8
My code looks fine but it is not working as it should because update
<a href=details.php?phoneid=1><img src=phone01.jpg></a> When I write the code like this it's working fine. But
For single output types my code is working fine but I couldn't get how
Here is my code after modifications, things seems working fine but I am receiving
I have jquery validation code which is working fine in ff but the same
I'using the following code to create thumbnails using ffmpeg but it was working fine
I am using blow code for join in nhibernate, which is working fine. But
So basically this code was working fine before. I had some computer issues and
We have this legacy image viewer component in our project that's working fine but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.