0

I am trying to get input value after keypress by jQuery. I have tried few ways to get it and I receive undefined or "". Using JSF+RichFaces. Input is the <h:inputTextarea> Trying to get value by:

<script type="text/javascript">
    jQuery(document).ready(function() {
         jQuery("#myform:idTextarea").keyup(function(){
            var testValue = jQuery("myform:idTextarea").val();
            console.log(testValue);

        });
     }); 
</script>

The variable in log is undefined. When I add "input:" like that

var testValue = jQuery("input:myform:idTextarea").val();

I get j_id12.

When change like that:

var testValue = jQuery("#myform:idTextarea").val();

I get "".

Have someone any clues?

4
  • # id referance missing here . jQuery("myform:idTextarea").val(); Commented Feb 26, 2015 at 9:42
  • Can you show your HTML too as the selectors are currently ambiguous? Commented Feb 26, 2015 at 9:46
  • Selectors are not ambiguous I have checked that. Html is simple textarea with id. Like <textearea id="..." class="..." etc. ></textarea> Commented Feb 26, 2015 at 9:53
  • You are supposed to remove the JSF noise as this is not a JSF/RichFaces problem. Commented Feb 26, 2015 at 10:03

2 Answers 2

2

You need to escape CSS meta-character while buidling the jquery selector:

jQuery("input\\:myform\\:idTextarea").val();

Escaping css meta character in jquery

Sign up to request clarification or add additional context in comments.

1 Comment

That was the problem, but in line when I get component by id - later I used this selector. Thanks!
0

You don't need to find same element for which keyup is registered, just use this

<script type="text/javascript">
    jQuery(document).ready(function() {
         jQuery("#myform:idTextarea").keyup(function(){
            var testValue = jQuery(this).val();
            console.log(testValue);

        });
     }); 
</script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.