Problems with a script

1

I have the following script

echo "<script language='javascript' src='ajax.js' type='text/javascript'></script>";
echo  "<script language='JavaScript' >


function c_resolucion(resolucion)
{
            var resolucion, cajas; 
      //contenedor = 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) { 

           contenedor.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);

}
  </script>";

the ajax file is as follows

<?php 
session_start(); 

global $rutalib;

//Incluir otros archivos: 
require_once("../../../../fuentes/librerias_mahalo/rutalib.php");
require_once($rutalib."librerias_mahalo/mainfile.php");

//Variables globales. 
global $usuario;
global $g_idq;
global $link, $sql_status, $g_status,$g_code_err;

//*************************************
//*************************************

function gp_execute2($query) {
        error_reporting(0);
     global $link, $sql_status, $g_status,$g_code_err;
     $g_status=0;
     $resultado_error=0;
     $sql_status = ifx_query($query, $link);
     $c_error = ifx_error();
     $g_code_err=substr($c_error,28,1);
     $c_error= substr($c_error,29,3);

     if ( $c_error!= "]" ) {

        $resultado_error=1;

          $g_status=0;

     }

 return $resultado_error;

  }


$d_resolucion=$_POST['resolucion'];
$caja=$_POST['caja'];

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

 $sql_status_in=gp_execute2($sql);
 //echo "--1-<br> $sql <br><br>";
    ?>

When I try to perform the process I get the following message

  

SCRIPT5007: Can not get reference property 'options'   null or undefined

I do not understand what you mean.

this is the html

"<td align=\"center\" >";
"<select id='resolucion' name='resolución' onchange='c_resolucion()'>";
"<option value=''>NINGUNO</option>";
"<option value='AUT'>AUT</option>";
"<option value='HAB'>HAB</option>";
"</select>";
    
asked by Norbey Martinez 30.06.2016 в 16:00
source

2 answers

1

I have something to do with your form1 , in your code HTML that you have placed is not observed where the form1 is, because you do not better access your select via id . I leave a code where it explains what I mean.

var btn1 = document.getElementById("btn_1"); // Eso es solo por ejemplo, le puse un botón
btn1.onclick = function (){ // Le agrego un evento click a mi botón.
                /*Aquí es donde digamos inicia la busqueda del select*/
                var slc = document.getElementById("slc"); // Buscamos el select por su id, el id puede ser el que tu eligas.
                var indice = slc.selectedIndex; //Accesamos a su opción seleccionada mediante el indice del select
                var opcion = slc.options[indice]; // Ahora accedamos al option del select vía el indice
                console.log(opcion.value,":",opcion.textContent);
              }
<select id="slc">
    <option>--Elige opción--</option>
    <option value="1">Primer Select - Primera Opción</option>
    <option value="2">Primer Select - Segunda Opción</option>
  </select>

<button id="btn_1">Mostrar datos</button>
    
answered by 30.06.2016 в 18:58
1

It gives me that the error is in this line:

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

document.form1.resolucion is null or undefined and that's why it does not reach options . I think you're not accessing the form correctly, try this:

const form = document.querySelector('#form1')
form.options[form.resolucion.selectedIndex].value

In any case, to access the form values with jQuery you can do:

$('#form1').serialize()

And in JavaScript 'bareback' you can use an object FormData :

const formData = new FormData(document.querySelector('form'))
    
answered by 30.08.2016 в 13:04