Php and AJAX Live Search

Hello,


There are 3 pieces of information, title and content, for each person in the database.
In live search, I want to make a live search only from the red-framed area.
My question is:
Ekran görüntüsü 2022-05-23 175919

The search result seen in the picture is the title 1 results.
When I click on one of these results I want it to add content to all fields.
How can I do that?

<script type="text/javascript">
    $(document).ready(function(){

        $("#baslik_1").on("keyup input", function(){
            var inputVal = $(this).val();
            var resultDropdown = $(this).siblings(".liveresult");
            if(inputVal.length){
                $.get('livesearch.php', {term: inputVal}).done(function(data){
                    resultDropdown.html(data);
                });
            }else{
                resultDropdown.empty();
            }
        });
        
        $(document).on("click", ".liveresult li", function(){
            $("#baslik_1").val($(this).text());
            $(this).parent(".liveresult").empty();
        });

    });
</script>
<input type="text" class="form-control" id="baslik_3" name="baslik_3" placeholder="Başlık 3" autocomplete="off" required>
<textarea class="form-control" rows="5" name="adres_3" id="adresi_3" placeholder="Adres 3"></textarea>

<input type="text" class="form-control" id="baslik_2" name="baslik_2" placeholder="Başlık 2" autocomplete="off" required>
<textarea class="form-control" rows="5" name="adres_2" id="adresi_2" placeholder="Adres 2"></textarea>

<input type="text" class="form-control" id="baslik_1" name="baslik_1" placeholder="Başlık 1" autocomplete="off" required>
<ul class="list-group liveresult"></ul>
<textarea class="form-control" rows="5" name="adres_1" id="adresi_1" placeholder="Adres 1"></textarea>

Well, there are three ways to do this. Each one is useful for different reasons. It depends on where this data is coming from. Let’s talk about the data only for right now.

1 - Data comes from a database when the page loads and is stored in hidden DIV’s.
2 - Data comes from a database when the page loads and is stored in Javascript routine as VAR’s
3 - Data is not loaded until the drop-down is clicked and dynamically loaded using JS/AJAX calls to server

I assume you probably are talking about #3. Here is a link to StackOverflow that discusses all of these 3 options and how to handle them. ( They call them A,B,C ) Kind of a long post, but, covers everything you need to learn about these processes. One issue would be that you need to combine your look-ahead and the AJAX call together, but, should not be a problem. Good luck! Dynamic Load from Drop-down

Thank you for the answer,
The value selected from the search result list is querying again with another ajax
and I get the data with json

I write the information as below in the whole field

$.ajax({
	url: 'ara.php',
	method: "POST",
	dataType: "json",
	data: { secilen : secilen },
	success: function (gelen) {
			$("#firma_a").val(gelen.firma_adi_a);
			$("#adresi_a").val(gelen.firma_adresi_a);
			$("#firma_b").val(gelen.firma_adi_b);
			$("#adresi_b").val(gelen.firma_adresi_b);
			$("#firma_c").val(gelen.firma_adi_c);
			$("#adresi_c").val(gelen.firma_adresi_c);
	}
});
Sponsor our Newsletter | Privacy Policy | Terms of Service