Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. How can I get an input value from ajax result search

How can I get an input value from ajax result search

Scheduled Pinned Locked Moved JavaScript
databasephphtmlmysqlquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vlafratta
    wrote on last edited by
    #1

    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();
    }
    });
    });

    Z Richard DeemingR 2 Replies Last reply
    0
    • V vlafratta

      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();
      }
      });
      });

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      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.

      V 1 Reply Last reply
      0
      • Z ZurdoDev

        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.

        V Offline
        V Offline
        vlafratta
        wrote on last edited by
        #3

        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.

        Z 1 Reply Last reply
        0
        • V vlafratta

          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.

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          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.

          V 1 Reply Last reply
          0
          • Z ZurdoDev

            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.

            V Offline
            V Offline
            vlafratta
            wrote on last edited by
            #5

            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

            Z 1 Reply Last reply
            0
            • V vlafratta

              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

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              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.

              V 1 Reply Last reply
              0
              • Z ZurdoDev

                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.

                V Offline
                V Offline
                vlafratta
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • V vlafratta

                  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();
                  }
                  });
                  });

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  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

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups