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?

Tiny
  • 27,221
  • 105
  • 339
  • 599
Rembrandt
  • 25
  • 1
  • 1
  • 8

2 Answers2

2

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

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

Escaping css meta character in jquery

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
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>
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57