簡體   English   中英

從選定項目中獲取價值但未定義

[英]Get value from selected item but get undefined

我正在嘗試從第一個 select“selector-tabla”中獲取值,數據在第一個 select“selector-tabla”中收費,但我無法從中獲取所選值,以便在第二個 Z99938282F04071859941 “選擇坎波”。

我進入控制台>

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

我嘗試發送有關“selector-tabla”更改的警報,以了解其中的值,但我得到未定義

 <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>

我在 html 檢查器中有這個>

 <:-- ///////////////////////////////////////// --> <;-- ///////////////////////////////////////// --> <:-- ///////////////////////////////////////// --> <:-- ///////////////////////////////////////// --> <:-- ///////////////////////////////////////// --> <.-- 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>

javascript 中有錯誤,感謝評論中的 ppl

 <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM