CodeLab
CodeLab

Reputation: 134

Jquery code to match input value

I'm trying to write a jquery code that will match input of user once they enter @ it will show that they key in @. With this code am not getting any thing please someone should help me with that?

HTML

<input id="input" value=""/>
<div id="out"></div>

Jquery

 $(document).ready(function () {
     var value = "@";
     $('#input').keyup(function(e) {
     //$('#input').match(value){
     $('#input').val=(value) {
             //alert('You enter @');
    $('#out').html("You enter @");     
         }
     });

 });

Upvotes: 0

Views: 2398

Answers (2)

Jyothi Babu Araja
Jyothi Babu Araja

Reputation: 10282

use

if($('#input').val() === value))

instead of

if($('#input').val=(value))

Upvotes: 1

Satpal
Satpal

Reputation: 133403

The usage .val() is a not correct, its a function not a property. Note the code below is for exact match.

var value = "@";
$('#input').keyup(function(e) {
    if ($(this).val() == value) {
        $('#out').html("You enter @");
    }

    //You can also use the value property like 
    //if (this.value == value) {
    //    $('#out').html("You enter @");
    //}
});

var value = "@";
$('#input').keyup(function(e) {
    if ($(this).val() == value) {
        $('#out').html("You enter @");
    }

    //You can also use the value property like 
    //if (this.value == value) {
    //    $('#out').html("You enter @");
    //}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input" value=""/>
<div id="out"></div>

Upvotes: 1

Related Questions