Rod
Rod

Reputation: 15455

help with $(this).val() toUpperCase()

Given:

<script type="text/javascript">
    $(document).ready(function () {
        var str = 'Test';
        //alert(str.toUpperCase());

        $('#stringFinder').keyup(function (e) {
            alert($(this).val()==str.toUpperCase());
        });
    });
</script>

How do I make $(this).val() all upper case to get a like comparison using contains?

Thanks, rodchar

Upvotes: 5

Views: 38001

Answers (3)

fabian
fabian

Reputation: 21

Try this:

 $(".solomayus").keypress(function (event) {
      $(this).val($(this).val().toUpperCase());
 });

OR

  $('.solomayus').blur(function () {
      $(this).val($(this).val().toUpperCase());
  });

Upvotes: 2

Alex
Alex

Reputation: 35409

 $('#stringFinder').keyup(function (e) {
     alert($(this).val().toUpperCase() == str.toUpperCase());
 });

Upvotes: 6

karim79
karim79

Reputation: 342635

$(this).val() returns a String object, which means you perform any String methods on it, so:

alert($(this).val().toUpperCase() === str.toUpperCase());

Upvotes: 15

Related Questions