How to substitute the value ui autocomplete in the onclick?

Hello, please tell me, I have a live search from database, but I need when select a value from the drop-down list to run the onclick with the same value that was found

<input type="text" id="name_load" value="" />
<input type="submit" onclick="changeLocation("", "name|$value of what introduced a person")" />

when you press the button, you need to run this onclick with what the user entered

the <script>
 $(function() {
 $( "#name_load" ).autocomplete({
 source: "{/literal}{$live_site}{literal}/include/get_info.php?type=name_acc",
 minLength: 1

how can I do that?
April 3rd 20 at 18:35
1 answer
April 3rd 20 at 18:37
If I understand correctly that you here Link
There is a select event as it is triggered when an item is selected from wypadki. Yes, there is not enough to be honest. Can help.
@oren15 , thank you, but it is only between tags copies the contents of, for example, between <span id of"Term"></span> it is also pointless.. ie I need to substitute the value of the user event may Ajax ohms, but how, I wonder
I have the following code which requests information from the database

case 'country_acc':

 require_once $config_abs_path."/classes/categories.php";
 if(isset($_GET['term'])) {
 $term = escape($_GET['term']);
 $result = categories::getAutocompleteRegion($term);

 require_once $config_abs_path."/libs/JSON.php";

 echo json_encode($result);

so maybe it is possible to make an Ajax request and the variable $term is already inserted in the template where you want? ie it turns out that the user writes in the input is written to the variable $term, so maybe it can somehow be reversed and to Ajax? - mohamed46 commented on April 3rd 20 at 18:40
So see you need to do this?
1. Write in the box some text (for example it will be the city of the Russian Federation), us climbs tips.
2. Select Moscow.
3. After that, we click on the submit button and calls the function changeLocation, the second argument to this function just gets the name of our city.
Right? - oren15 commented on April 3rd 20 at 18:43
@oren15, yeah, already tried different setups and nothing has turned up.. - mohamed46 commented on April 3rd 20 at 18:46
I seem to remember doing something like this but for a long time. Try to distribute the code.
$(function() {
 $( "#name_load" ).autocomplete({
 source: "{/literal}{$live_site}{literal}/include/get_info.php?type=name_acc",
 minLength: 1,
 select: function(event, ui){
 //Remove old event listener-click when you select a new value

 setListenerButtonSave function(ui) {
 $('input[type=[submit]]').on('click', function () {
 changeLocation('first option', (that is, the city, or what have you));

Well, something, in General I think we need to move away from the onclick attribute from the input, and to visit them in code each time when we hang an event listener to the button, and it happens every time after choosing value from select we negotiates ui in which there is stored the name of the city, well, clean up the previous listener with old data if any. Could be wrong of course, but I think it is more correct solution to the problem. - oren15 commented on April 3rd 20 at 18:49
@oren15, thank you, but one thing is not clear how to insert the selected option?

$('input[type=[submit]]').on('click', function () {
 changeLocation('first option', (that is, the city, or what have you));

ie here as clearly insert the values for example to be like that?

changeLocation(', 'country|Russia');

how is it to be substituted? - mohamed46 commented on April 3rd 20 at 18:52
First you need to understand what's the name of the final field in the object where the city lies, I think that is a constant part, but the next field will be called is not city. I was about as, that is city was the last box and it already had a row with the city.
That is, in your case, I would have done so
changeLocation(', 'country|' +;

You need the select event to put console.log(ui); and see what is there structure and then to write the function changeLocation. - oren15 commented on April 3rd 20 at 18:55
@oren15, I looked in the console I have here displays what is specified in input

<div contenteditable="plaintext-only">Russia</div>

but now it is impossible to choose from the list the name, ie it does not work click to frame, the page refreshes even if you add the title in hand and all.. - mohamed46 commented on April 3rd 20 at 18:58
Well, here I can be of little help. Here is drips into the code and configure this thing. I tried to tell you the possible solution that you would have to dig further in this direction, I'm not looking unable to do anything. Alas :( - oren15 commented on April 3rd 20 at 19:01
@oren15, thanks anyway, I will look further that you can think of) - mohamed46 commented on April 3rd 20 at 19:04
Not for that, if nothing happens, write in a cart, can we get somehow) If you have time of course) - oren15 commented on April 3rd 20 at 19:07

Find more questions by tags JavaScript