Typeahead clears input when value is provided by javascript

Asked

Viewed 137 times

2

I’m using the Typeahead version 0.9.3 to auto-complete my inputs. It’s working fine, get the bank info and show it all right.

However, if I want to define some value for the input through Javascript. When the user clicks over the field and then out the value of the field is null.

If I put the value on the property value of input. This does not occur. My problem is that I need to assign value to the input through the Javascript.

$(document).ready(function() {
    $('#teste').typeahead({
        limit: 50,
        minLength: 1,
        remote : '../db/dbAutoComplete.php?&query=%QUERY'
    });

    $('#teste').val('Valor que some se clicar fora do campo');
    //Estou forçando o valor a título de exemplo

});

And My HTML has only input.

input type='text' name='teste' id='teste' value='' required
  • What is the return when you take the value $('#teste').val()?

  • First. Thanks for the help. I did the following: input type='text' name='teste' id='teste' value='' required onblur ="BuscaRetorno()" Function Searchreturn(){ Alert($('#test').val(); } At this point it brings information from the right field. After that the value of the field disappears.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.