How can I get an input value from ajax result search
-
Hello, I'm new here. I am designing an intranet, of which I require that the user when making a request for a product will be able to select it directly from the database and send that request. From the page where the requests originate, I added a search button for the user to search for the specific product and add it to their product request, this was done with ajax live search. From the results of that search, a list is usually displayed with the possible results, the objective, and it is where I am blocked, is that from the list with the results, the user chooses the one he wants and this is inserted in the request for the parent page. I have these live search files in ajax, php and mysql: search-form.php (popup):
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"backend-search.php",
method:"POST",
data:{query:query},
success:function(data){
$('#result').html(data);
}
});
}
$('#search').keyup(function(){
var search = $(this).val();
if(search != ''){
load_data(search);
}else{
load_data();
}
});
}); -
Hello, I'm new here. I am designing an intranet, of which I require that the user when making a request for a product will be able to select it directly from the database and send that request. From the page where the requests originate, I added a search button for the user to search for the specific product and add it to their product request, this was done with ajax live search. From the results of that search, a list is usually displayed with the possible results, the objective, and it is where I am blocked, is that from the list with the results, the user chooses the one he wants and this is inserted in the request for the parent page. I have these live search files in ajax, php and mysql: search-form.php (popup):
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"backend-search.php",
method:"POST",
data:{query:query},
success:function(data){
$('#result').html(data);
}
});
}
$('#search').keyup(function(){
var search = $(this).val();
if(search != ''){
load_data(search);
}else{
load_data();
}
});
}); -
Is the variable query getting passed to the backend php?
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.
Hey ZurdoDev, do you mean after choose a product from the list? Yes, the main purpose is select the product and pass it (codice, articolo) pass it to the main window form, from there it will be inserted to mysql database. Main window(php) -> popup window/search product/select product(php/js) -> main window form(php) -> ok with your choice? yes -> pass it to the database (array to string). That will be the main structure. Thanks in advance.
-
Hey ZurdoDev, do you mean after choose a product from the list? Yes, the main purpose is select the product and pass it (codice, articolo) pass it to the main window form, from there it will be inserted to mysql database. Main window(php) -> popup window/search product/select product(php/js) -> main window form(php) -> ok with your choice? yes -> pass it to the database (array to string). That will be the main structure. Thanks in advance.
I don't understand where you are stuck, that is what I was trying to get to.
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.
-
I don't understand where you are stuck, that is what I was trying to get to.
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.
Ok, the main point in this post is to catch/select anye result from the search of the live search ajax, as you can see in the code, for every result there is a button (aggiungi or add) that should cover the base, but, on any product that i click, always is pass it the first result. Now I don't if this have to do with the fact that the document.getElementById is the problem and change it to byclassname or I don know. I am stuck in this particular matter. Thank you
-
Ok, the main point in this post is to catch/select anye result from the search of the live search ajax, as you can see in the code, for every result there is a button (aggiungi or add) that should cover the base, but, on any product that i click, always is pass it the first result. Now I don't if this have to do with the fact that the document.getElementById is the problem and change it to byclassname or I don know. I am stuck in this particular matter. Thank you
vlafratta wrote:
as you can see in the code,
Actually, no, I can't run the code so just looking at a bunch of code it is not obvious what is happening or what should be happening.
vlafratta wrote:
always is pass it the first result.
You probably have controls with the same id over and over. You'll need to make sure they have unique ids.
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.
-
vlafratta wrote:
as you can see in the code,
Actually, no, I can't run the code so just looking at a bunch of code it is not obvious what is happening or what should be happening.
vlafratta wrote:
always is pass it the first result.
You probably have controls with the same id over and over. You'll need to make sure they have unique ids.
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.
Finally could apply a solution: Replace the way how it's show the result from the ajax live search to this:
COD: ' . $codice . ' - DESC: ' . $articolo . '
For the Javascript, replace it with JQuery:
$(document).ready(function(){ $(".child span").click(function(){ code = $(this).parent().attr('data-id'); articolo = $(this).parent().attr('data-id2'); window.opener.$('#codice').val(code); window.opener.$('#articolo').val(articolo); window.close(); });
})
Thank you all. Valter.
-
Hello, I'm new here. I am designing an intranet, of which I require that the user when making a request for a product will be able to select it directly from the database and send that request. From the page where the requests originate, I added a search button for the user to search for the specific product and add it to their product request, this was done with ajax live search. From the results of that search, a list is usually displayed with the possible results, the objective, and it is where I am blocked, is that from the list with the results, the user chooses the one he wants and this is inserted in the request for the parent page. I have these live search files in ajax, php and mysql: search-form.php (popup):
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"backend-search.php",
method:"POST",
data:{query:query},
success:function(data){
$('#result').html(data);
}
});
}
$('#search').keyup(function(){
var search = $(this).val();
if(search != ''){
load_data(search);
}else{
load_data();
}
});
});vlafratta wrote:
$query = $sql = "SELECT * FROM spesa_articoli_disponibili WHERE Codice_Articolo_CAPP LIKE '%" . $search . "%' OR ARTICOLO_Descrizione LIKE '%" . $search . "%'";
Don't do it like that! Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. PHP: SQL Injection - Manual[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer