-1

code:

<script>
    $(function() {
    $( "#university_name" ).autocomplete({
    source: 'autocomplete.php',
    minLength:2,
    select: function(event, ui) {
    var x = ui.item.value;
    }
    });
    });
</script>

<input type="text" id = "university_name"  name = "university_name" value= "x" placeholder = "University Name" >

Here I want to place jquery variable value i.e var x into input field value So How can we do this ?

Thank You

sam orten
  • 206
  • 3
  • 16
  • 2
    Simply `$("#university_name").val( your_var );` – Patryk Uszyński Jan 25 '17 at 09:22
  • `$("#university_name").val( ui.item.value);` enough for u. – Hikmat Sijapati Jan 25 '17 at 09:23
  • 3
    Possible duplicate of [How to set value of input text using jQuery](http://stackoverflow.com/questions/10611170/how-to-set-value-of-input-text-using-jquery) – Rajesh Jan 25 '17 at 09:25
  • `autocomplete` is getting invoked on same university_name field; then why you want to send its value explicitly? It will get set automatically whenever you select the value from search results. – vijayP Jan 25 '17 at 09:27
  • Thanks for your reply hikmat sir But I have one more query sir if I want to use this value in a mysql query is it possible or not if yes then how ? – sam orten Jan 25 '17 at 09:33

1 Answers1

1

you can do it using jquery val()

$('#university_name').val(x);

your full code will go like this

$( "#university_name" ).autocomplete({
    source: 'autocomplete.php',
    minLength:2,
    select: function(event, ui) {
    var x = ui.item.value;
    $('#university_name').val(x);
    }
    });
Ameya Deshpande
  • 3,580
  • 4
  • 30
  • 46