php - Get option title from dropdown list with javascript -


i got dynamic input form dropdown list. here's code dropdown

<label class="strong">cut:  <select name="add_qty"> <?php     $qqs = mysqli_query($conn, "select * m_maincut maincut_status = '1'");     while($roq = mysqli_fetch_array($qqs, mysqli_assoc))     { ?>         <option id="opsi" value="<?php echo $roq['maincut_id']; ?>" title="<?php echo $roq['maincut_name']; ?>"><?php echo $roq['maincut_name']; ?></option> <?php     } ?> </select> </label>  total: <input type="text" name="add_name" />  <input onclick="addrow(this.form);" type="button" value="add new" /> 

and here's javascript make form dynamic (click button add more option)

<script type="text/javascript"> var rownum = 0;  function addrow(frm) {     rownum++;     var text = frm.opsi.title;     var row = '<p id="rownum' + rownum + '">nama biaya: <option type="text" name="qty[]" size="4" value="' + frm.add_qty.value + '">' + text + '</option> jumlah: <input type="text" name="name[]" value="' + frm.add_name.value + '"> <input type="button" value="remove" onclick="removerow(' + rownum + ');"></p>';     jquery('#itemrows').append(row);     frm.add_qty.value = '';     frm.add_name.value = ''; }  function removerow(rnum) {     jquery('#rownum' + rnum).remove(); } </script> 

here's result:

enter image description here

"tambah ke biaya" means "add more"

my question is, how title of option? can value, can title show client. because if show value, show number (the id's)

you have innerhtml of option tag if want shown user. , must create option instead p element


Comments