falconimogollon
falconimogollon

Reputation: 111

Get value from selected item but get undefined

I am trying to get the value from the first select "selector-tabla", the data is charged in the first select "selector-tabla", but i can't get the selected value from it, to charge data in the second select "select-campo".

I get in the console>

Object { is_ajax: 1, tabla: NaN, consulta: "TRUE" }

I try to send alerts on change of "selector-tabla", to know the value from it, but i get undefined

<script type="text/javascript">

$(document).ready(function() {
$.ajax({
type: "POST",
url: "tablas_cambiar-datos.php",
data: {consulta: "TRUE"
,start: "TRUE"
},
success: function(response)
{
$(".selector-tabla select").html(response).fadeIn();
selector_campo();
}
});
});



function selector_campo(){

var form_data = {
is_ajax: 1,
tabla: +$(".select-campo select").val()
, consulta: "TRUE"
};
console.log(form_data);

$.ajax({
type: "POST",
url: "tablas_cambiar-datos.php",
data: form_data,
success: function(response)
{
$(".selector-campo select").html(response).fadeIn();

}
});
}

$(document).ready(function() {
$(".selector-tabla select").change(function() {
alert($('#AttorneyEmpresa option:selected').val());
selector_campo();
});
});


</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
  <div class="form-group col-md-6 selector-tabla">
    <label>Tabla</label>
        <select class="select" name="tabla">
        </select>
   </div>
  <div class="form-group col-md-6 selector-campo">
    <label>Campo</label>
        <select class="select" name="campo" id="AttorneyEmpresa">
    </select>
    </div>
</div>

I have this in the html inspector>

<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!--  selector-tabla-->
<div class="form-group col-md-6 selector-tabla">
<label>Tabla</label>
<select class="select select2-hidden-accessible" name="tabla" tabindex="-1" aria-hidden="true">
<option value="parroquias">0 parroquias</option>
<option value="sfx_admin_users">1 sfx_admin_users</option>
<option value="sfx_otros_empresa">2 sfx_otros_empresa</option><option value="sfx_otros_estado">3 sfx_otros_estado</option>
<option value="sfx_otros_locales">4 sfx_otros_locales</option><option value="sfx_productos_">5 sfx_productos_</option>
<option value="sfx_productos_cantidad">6 sfx_productos_cantidad</option>
<option value="sfx_productos_codbarras">7 sfx_productos_codbarras</option>
<option value="sfx_productos_empaque">8 sfx_productos_empaque</option>
<option value="sfx_productos_empaque_set">9 sfx_productos_empaque_set</option>
<option value="sfx_productos_peso_set">10 sfx_productos_peso_set</option>
<option value="sfx_productos_proveedores">11 sfx_productos_proveedores</option>    
</select>

<span class="select2 select2-container select2-container--default select2-container--above select2-container--focus" dir="ltr" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-tabla-r3-container"><span class="select2-selection__rendered" id="select2-tabla-r3-container" title="3 sfx_otros_estado">3 sfx_otros_estado</span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
</div>
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!-- ///////////////////////////////////////// -->
<!--  selector-campo-->

<div class="form-group col-md-6 selector-campo">
<label>Campo</label>
<select class="select select2-hidden-accessible" name="campo" id="AttorneyEmpresa" tabindex="-1" aria-hidden="true">


( ! ) Notice: Undefined variable: sql in D:\Users\falco\OneDrive\VARIOS\Local\PAGINA WEB\admin\tablas_cambiar-datos.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0013365016{main}(  )...\tablas_cambiar-datos.php:0



( ! ) Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\Users\falco\OneDrive\VARIOS\Local\PAGINA WEB\admin\tablas_cambiar-datos.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0013365016{main}(  )...\tablas_cambiar-datos.php:0
20.0318466408mysqli_error
(  )...\tablas_cambiar-datos.php:18



( ! ) Fatal error: Query Failed! SQL:  - Error:  in D:\Users\falco\OneDrive\VARIOS\Local\PAGINA WEB\admin\tablas_cambiar-datos.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0013365016{main}(  )...\tablas_cambiar-datos.php:0
20.0335466408trigger_error
(  )...\tablas_cambiar-datos.php:18

</select>
<span class="select2 select2-container select2-container--default" dir="ltr" style="width: 100%;"><span class="selection"><span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-AttorneyEmpresa-container"><span class="select2-selection__rendered" id="select2-AttorneyEmpresa-container"></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>
</div>

Upvotes: 0

Views: 225

Answers (1)

falconimogollon
falconimogollon

Reputation: 111

had an error in javascript, thanks for the ppl in the comments answers

<script type="text/javascript">

$(document).ready(function() {
$.ajax({
type: "POST",
url: "tablas_cambiar-datos.php",
data: {consulta: "TRUE"
,start: "TRUE"
},
success: function(response)
{
$(".selector-tabla select").html(response).fadeIn();
selector_campo();
}
});
});



function selector_campo(){

var form_data = {
is_ajax: 1,
tabla: $(".selector-tabla select").val()
,consulta: "TRUE"
};
console.log(form_data);

$.ajax({
type: "POST",
url: "tablas_cambiar-datos.php",
data: form_data,
success: function(response)
{
$(".selector-campo select").html(response).fadeIn();

}
});
}

$(document).ready(function() {
$(".selector-tabla select").change(function() {
selector_campo();
});
});

</script>

Upvotes: 1

Related Questions