Update using ajax and javascript

0

I have the following options, which should update two different sw:

in the first I have the options of ninguna, aut, y hab and in the second I have the option of sw_visible , which is 1 or 0 dependent if it is active or inactive.

<td align=\"center\" >;
<select id='resolucion' name='resolucion' onchange='c_resolucion()'>;
<option value=''>NINGUNO</option>;
<option value='AUT'>AUT</option>;
<option value='HAB'>HAB</option>;
</select>";

<td align=\"center\" >";
<input type=\"checkbox\" name=\"sw_visible\" value=\"1\"  onclick=\"c_resolucion()\">Si";
</td>";

I want both to use the same javascrips function. and that I update the option depending on what the client uses in the form.

this is the next function

function c_resolucion(resolucion)
{
            var resolucion, cajas; 
      resolucion = document.getElementById('resolucion');  
     // document.form1.orden.value = ''

      resolucion = document.form1.resolucion.options[document.form1.resolucion.selectedIndex].value

      ajax=nuevoAjax(); 

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

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

           resolucion.innerHTML = ajax.responseText 


        } 

      }

            ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            ajax.setRequestHeader('Connection','Close');
            ajax.setRequestHeader('Cache-Control','no-cache, must-revalidate');
            ajax.setRequestHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT');
            ajax.send('&resolucion='+resolucion+'&sw_visible='+sw_visible);

}
</script>";

and this is the ajax file which carries out the update.

$d_resolucion=$_POST['resolucion'];


?>
<td>
<?php
 $sql = "UPDATE m_puntos_pago set d_resolucion='"$d_resolucion"' WHERE caja = ".$caja;

 $sql_status_in=gp_execute2($sql);

    ?>

as it performs the update depending on the option that the client makes. either press the check or select some of the options in the field of_resolution.

    
asked by Norbey Martinez 08.07.2016 в 18:04
source

1 answer

1

According to what I understood, you only need to know where the function is being called to update the corresponding element. Just place an id in the input as well as the select and pass this parameter.

For example:

<input id="myinput" type=\"checkbox\" name=\"sw_visible\" value=\"1\" onclick=\"c_resolucion(this)\">Si";
//Javascript
function c_resolucion ( argumentos ){
   console.log( argumentos )
   //Accedes al id y luego evalúas de donde fue llamada y que deseas activar
}
    
answered by 21.07.2016 в 05:34