0

I have a textbox as shown below,

<input type="text" name="company" id="company" required />

My question is, I want to get the values inside the textbox using jquery whenever I typed or selected the values.

I have tried a lot but no effect. The jquery i have tried is below,

$(document).ready(function(){
    var input = $('#company').val();
    $("#tag").autocomplete("autocomplete1.php?str="+input, {
        selectFirst: true
    });
});

The above code has no effect. Is there any method. Kindly help. Thanks in advance.

Jithin Varghese
  • 2,018
  • 3
  • 29
  • 56

3 Answers3

2

You need to bind Jquery event on change like,

$(document).ready(function(){
    $('#company').focus(function(){
        var input = $('#company').val();
        $("#tag").autocomplete("autocomplete1.php?str="+input, {
            selectFirst: true
        });
    });
});

There are many other events you can bind, here is the official documentation of Jquery for that.

Jithin Varghese
  • 2,018
  • 3
  • 29
  • 56
viral
  • 3,724
  • 1
  • 18
  • 32
1

Try something like:

http://jsfiddle.net/whxbLos4/

$(document).ready(function() {    
    $('#company').on('change : focus : keypress', function() { 
        //  this.value is what you need       
        $('#result').html(this.value);
    });
});
Ioana Cucuruzan
  • 845
  • 1
  • 8
  • 21
0

You can also use on blur to get it on focusout as an alternative as below:

$('#company').on('blur',function(){
      var input = $(this).val();
      //Other codes
});
Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200