I try to save the value of a select in an input and I get the following error: Uncaught TypeError: Can not read property 'or' of undefined

1

here is my code:

<?php
include_once ($_SERVER['DOCUMENT_ROOT'].'/LinqSy/Emisiones/clase.php');
include_once $_SERVER['DOCUMENT_ROOT'].'/LinqSy/debug/ChromePhp.php'; 
$view2= new stdClass();
$view2->disableLayout=true;
$view2->acreedores=Fideicomiso::getGrupos($_POST[menu]);
if (isset($_POST[acred])) {
        $editId=intval($_POST[acred]);
        //vista para los datos generales
        $view2->fideV=new Fideicomiso($editId);
    }
?>

<form name ="ac" id="ac" >
  <!-- <input type="text" name="menu" id="menu" value = "<?php print $view->fideV->getID()?>"> -->
  <input type="text" name="o" id="o" value = "" >
  <div>
        <br><label>Grupo de Acreedores</label>
        <select  class="acree"; name="acree" id="acree">
                <option value="0">Selecciona</option>
                <?php foreach ($view2->acreedores as $acreedores){?>
                  <option value="<?php echo $acreedores['Grupo'];?>"><?php echo $acreedores['Grupo']; ?></option>
            <?php }?></h3>          
        </select>  
  </div>  
</form>

</body>

 <script>

    $('#acree').change('click',function(){

            // Así accedemos al Valor de la opción seleccionada
             document.ac.o.value=$("#acree option:selected").val();
             params={};
             params.relacion= $("#acree option:selected").val();
             alert(params.relacion);

             if(params.relacion!=null){
                     $("#conceptos").html('<div><img src="upload.gif"/></div>');
                 $("#conceptos").load("RExpedientes/conceptos/vistac.php",params, function(response, status, xhr){
                            if (status == "error") {
                              var msg = "Error!, algo ha sucedido: ";
                              $("#capa").html(msg + xhr.status + " " + xhr.statusText);
                            }
                          });
                  }
     });
</script> 

says that my input is not defined, I can not find more to do

    
asked by Rogelio Azcona 27.06.2018 в 22:22
source

3 answers

0

It's because the ac object does not exist inside the document, you could do it like this:

document.getElementById('o').value = $("#acree option:selected").val();

Or you could use JQuery alone:

$('#o').value($("#acree option:selected").val())

As a best practice it is better to use more descriptive names for the ids of your inputs.

    
answered by 27.06.2018 / 23:54
source
0

ok what you are doing is

document.ac.o.value=$("#acree option:selected").val();

but this is not navigated through the DOM Document , the ideal is to get the HTML Objects through the methods that this collection has for example:

getElementById()    
getElementsByClassName()    
getElementsByName() 
getElementsByTagName()

now if you want to directly access the id what you can do is:

document.all.o

but I do not recommend it, it is better to use the methods that this collection has, I leave a link with the list of methods for you to see them.

DOM Document

PD: If you are already using jQuery I do not see much use in using the native javascript nomenclature unless you want to improve your website's performance

    
answered by 28.06.2018 в 00:43
0

Thank you very much everyone for your answers, I already corrected my code, the problem, apparently, was that I did not load jquery in my form, but I'm done.

    
answered by 03.07.2018 в 21:47