Process VARIOUS selections of ComboBOX in PHP

0

Dear, it is my first post in this community (and the only one) because I really have more than 3 weeks looking for a solution and I feel it is more complicated than I thought. I will be very explanatory. First with what I have and what I want to do and then the code.  I have a page where I embed an IFRAME with a GRID in PHP. In that Grid (as you can see in the image) there are several documents (more than 400).

Well, if they are set next to each document there is a COMBOBOX with the list of custodians (people who have to confirm each document). What is needed? That the operator of the application can assign to each document a custodian and then the button to process, so that these changes can be sent to the database. It is assumed that the operator can assign 1 or more custodians, so the program should verify which were the modified documents on the page and go to the database and save the changes according to the assignment assigned.

Think of 2 logical: 1) store the changes in a two-dimensional array, which stores the code of the document and the assigned custodians. Make a loop to find each changed document in a database and update the custodian data. 2) It is that each time the operator makes a change it is updated instantly in the database. There is also a small button next to the combo to see if he could execute this task. That has a form.

In both cases I already have 3 weeks and I can not get a code to help me.

I would really appreciate it very much if someone can support me with a code that allows me to make the changes in the database, according to the selection in the combobox.

This is the code with which I fill the combobox:

               echo '<form name="datosdoc" method="post" action="cssmenu/asignadoc.php">';
           echo"<select name=listausr>"; 
               for($i=0;$i<count($usuariosaasig);$i++){

                        echo '<option name="asignar" value="'.$usuariosaasig[$i].'">'.$usuariosaasig[$i].'</option>';

               } 
               echo "</select>"; 
               echo'<input type="submit" name="boton" value="º" />'; 
               echo '</form>';

and this is the button to process:

<div class="botonproc">
           <p><a href="cssmenu/asignadoc.php?varPorURL=<?php echo $docselect?>" target='tuArchivo' onclick="window.open(this.href, this.target, 'top=100% left=500% width=400, height=200, menubar=no');return false;"><input type="submit" value="Procesar.."></p> 

    </div>

Beforehand I thank you very much for your support. Whatever it is and this one is telling you that if you need more information, I will gladly provide them.

    
asked by Pedro Garcia 08.09.2017 в 18:06
source

2 answers

0

If in the select you put (PHP):

echo"<select name='listausr' data-docselect='$docselect'>";

Then in Javascript (JQuery):


    $('[name="listausr"]').on('change',
      function(){
         $.get('cssmenu/asignadoc.php?varPorUrl='+$(this).attr('data-docselect')+'&usuarioPorVar='+$(this).val(),
                function(){
                     window...(pon aqui lo que quieras que haga con la respuesta de php)...
          });
      });

Asi (I'll keep option 2) every time I change the combo I'll call 'cssmenu / assigndoc.php'

    
answered by 08.09.2017 в 22:34
0

Well thanks for the support, but I got an alternative solution. Stop thinking as a Client / Server and move on to the WEB logic. First add the ONCHANGE EVENT to the SELECT:

echo '<select id="listausr" name="listausr" onchange="ShowSelected();">'; 

This would be the function of the ONCHANGE event:

function ShowSelected()
    {
     /* Para obtener el valor */
     var cod = document.getElementById("listausr").value;

     /* Para obtener el texto */
     var combo = document.getElementById("listausr");
     var selected = combo.options[combo.selectedIndex].text;
     separa ="-";
     limite=2;
     arreglocodigo=cod.split(separa,limite);
     var asignado=arreglocodigo[0];
     var folioasigna=arreglocodigo[1];
     var otrofolio=arreglocodigo[arreglocodigo.length-1];

  window.open("cssmenu/asignadoc.php?usrcust="+asignado+"&codfolio="+folioasigna, this.target, 'top=100% left=500% width=400, height=200, menubar=no')
}

Inside the file asigndoc.php is where I capture the variales sent with $ _GET (or post as they wish) and from there I search in the database. Because as you select an option in the COMBOBOX on the page only that data remains, you need to reload the main page and close the asigndoc.php, with that the page is again to select another document.

It's like a little "worked", even more if there are 450 documents, but it was the most "solid" I got to solve the issue.

    
answered by 13.09.2017 в 22:30