javascript - Dinamic Select hidden input -
i hope explain problem want create form allows dynamically add selections , inputs select retrieve odbc array form this:
<form name="add_name" id="add_name"> <div class="table-responsive"> <table class="table table-bordered" id="dynamic_field"> <tr> <td> <select name="name[]" id="category" class="form-control" width="300px" onchange="aggiornahidden(this)"> <option value="">seleziona ordine - articolo</option> <?php echo $popola ?> </select> <input type="hidden" name="sel_value"> <input type="hidden" name="sel_text"> </td> <td> <input type="text" name="quantita[]" placeholder="inserisci quantita" class="form-control name_list" /> </td> <td><button type="button" name="add" id="add" class="btn btn-success">aggiungi riga</button></td> </tr> </table> </div> </form>
this php code:
<?php $conto='2411000044'; $dsn = 'iseries'; $connessione = odbc_connect("iseries", "utente, "pwd", 2) or die ("impossibile connettersi " . odbc_errormsg()); if($conto==""){ echo "impossibile trovare il codice artigiano....<br>"; } else{ $interrogazione ="select a.tipo, a.numero, a.codice, a.descrizione, b.barcode file1 a, file2 b (a.codice=b.codice1) , a.fornitore='".trim($conto)."' order a.codice, a.numero asc"; $risultato = odbc_exec($connessione, $interrogazione); while (odbc_fetch_row($risultato)) { $popola .= '<option value="'.odbc_result($risultato,"tipo").'-'.odbc_result($risultato,"numero").'-'.trim(odbc_result($risultato,"codice")).'-'.trim(odbc_result($risultato,"barcode")).'">'.odbc_result($risultato,"tipo").' - '.odbc_result($risultato,"numero").' - '.odbc_result($risultato,"codice").' - '.odbc_result($risultato,"descrizione").'</option>'; } } ?>
javascript code:
<script type="text/javascript" language="javascript" > $(document).ready(function(){ var i=1; $('#add').click(function(){ i++; $('#dynamic_field').append('<tr id="row'+i+'"><td><select name="name[]" id="category" class="form-control" width="300px" onchange="aggiornahidden(this)"><option value="">seleziona ordine - articolo</option><?php echo $popola?></select><input type="hidden" name="sel_value"><input type="hidden" name="sel_text"></td><td><input type="text" name="quantita[]" placeholder="inserisci quantita" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">x</button></td></tr>'); }); $(document).on('click', '.btn_remove', function(){ var button_id = $(this).attr("id"); $('#row'+button_id+'').remove(); }); function aggiornahidden(sel){ var f = document.add_name; f.sel_value.value = sel.options[sel.selectedindex].value; f.sel_text.value = sel.options[sel.selectedindex].text; } </script>
the first selection adds value hidden input after clicking on "add row" second select populated choosing different value value of hidden input remains blank wrong?
Comments
Post a Comment