use ajax to load information

6

I have the following form that has the following option:

echo "<tr>";
     echo "<td class='cs'>Forma pago</td><td>";
     echo "<div id='contenedor2'>";
     echo "<select name = 'cod_tarj'  style='border-color: #FF0000 #FF0000; border-width: 2px 2px; border-style: solid solid; font-size:8pt; color: #FF0000; letter-spacing; width:150px'></select>";
   echo "</div>"; 
   echo "</td>"; 
   echo "</tr>";

You have id =contenedor2 which is linked to a javascript function

function mostrar_formaPago()
{
            var contenedor, m; 
      contenedor = document.getElementById('contenedor2');  
      document.form1.orden.value = ''

      m = document.form1.estado.options[document.form1.estado.selectedIndex].value

      ajax=nuevoAjax(); 

      ajax.open('POST','ajax_tarjeta.php',true); 

      ajax.onreadystatechange=function() 
      { 
        if (ajax.readyState==4) { 

           contenedor.innerHTML = ajax.responseText 


        } 
      }

This in turn calls an ajax that has the code and description of a card:

$estado=$_POST['estado'];

$sql="SELECT * FROM  tarjetas WHERE sw_activo='$estado'";

$consulta=mysql_query($sql);

while($result=mysql_fetch_array($consulta)) 

{

echo "<option value = ".$result['cod_tarj'].">".$result['cod_tarj']."_".$result['desc_tarj']."</option>";
}

I need to make the card I'm loading depend on a list depending on your state 1=activas , 2=inactiva 3=carga todas

echo "<tr>"; 

         td1S(_LBFRM1_ESTADO,estado,'mostrar_formaPago()');
          td1SOp(3,_LBFRM1_ESTADOOP3,"$estado",0);
          td1SOp(1,_LBFRM1_ESTADOOP1,"$estado",0);
          td1SOp(2,_LBFRM1_ESTADOOP2,"$estado",0);    
         td1SC(); 
 echo "</tr>"; 

Bone if I select 1 from the list, in the form Payment form, only show me those that are active.

    
asked by Norbey Martinez 21.05.2016 в 17:43
source

2 answers

1

It seems that within the function show_forma Pago it is still necessary to send the data to the backend (to the procedure in php):

ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.send('estado=' + encodeURIComponent(m));

this would go as last lines of the function.

    
answered by 21.05.2016 в 21:39
0

TRY

function mostrar_formaPago(estado) {

    var contenedor, m;
    contenedor = document.getElementById('contenedor2');
    document.form1.orden.value = ''

    m = document.form1.estado.options[document.form1.estado.selectedIndex].value

    var data = "estado=" + estado;
    ajax = nuevoAjax();

    ajax.open('POST', 'ajax_tarjeta.php', true);

    ajax.onreadystatechange = function() {
        if (ajax.readyState == 4) {

            contenedor.innerHTML = ajax.responseText


        }
        ajax.send(data);
    }
}
    
answered by 22.05.2016 в 05:58