javascript - How do I populate textbox from a combobox selected -
i want combobox populates database column, when user selects option combobox populate textboxes, on same page, information related selection in combobox.
below code used populate textbox when selected select nama dropdown combobox. doesnt work, textbox still blank. have drop down working , fills javascript array using names cannot work out how use array show in fields.
i understand have use javascript , onchange function, can point me in right direction?
cheers , thank in advance :)
<script src="js/jquery.js"></script> <script type="text/javascript"> var selected = new array(); <?php $query1 = "select * inventori"; $result1 = mysql_query($query1) or die(mysql_error()); // build javascript array while($row1=mysql_fetch_array($result1)){ echo 'selected['.$row1['selectnama'].'] = new array();'; echo 'selected['.$row1['selectnama'].']["nama_bahan_baku"] = "'.$row1['nama_bahan_baku'].'";'; echo 'selected['.$row1['selectnama'].']["satuan"] = "'.$row1['satuan'].'";'; } ?> function showname() { var selectnama = document.forminventori.selectnama.value; document.forminventori.satuan.value = selected[selectnama]["satuan"]; } window.onload=function() { showname(); } </script> <form role="form" action="" method="post" name="forminventori"> <div class="form-group"> <label for="nama_bahan_baku">nama bahan baku</label> <select class="form-control" name="selectnama" onchange="showname()"> <option value="">pilih nama bahan baku</option> <?php $query1 = "select * inventori"; $result1 = mysql_query($query1) or die(mysql_error()); // build javascript array while($row1=mysql_fetch_array($result1)){ echo '<option value="'.$row1['id_bahan_baku'].'">'.$row1['nama_bahan_baku'].'</option>'; } ?> </select> </div> <div class="form-group"> <label for="satuan">satuan barang</label> <input type="text" class="form-control" readonly="" id="satuan" name="satuan" value=""> </div> </form>
i use ajax that, save value selected combobox , pass php through ajax php executes query selected value search "key", print result throught php
Comments
Post a Comment