Reputation: 1
I need help.. I create dynamically html form field adding using javascript..its work fine..but the problem is, I want to get the select box value from mysql database, how to do that..I'm stuck..
This is my code :
<script>
$(document).ready(function() {
var count = 1;
$('.addmore')['on']('click', function() {
count += 1;
html = '<tr>';
html += '<td><input class="case" type="checkbox"/></td>';html += '<td>
<input id="rows_' + count + '" name="rows[]" value="'+ count +'"
type="hidden" required><input type="text" name="tgl ' + count + '"
id="tgl_' + count + '" class="form-control changesNo" autocomplete="off"
data-mask="99/99/9999" ondrop="return false;" onpaste="return false;"
required></td>';
html += '<td><input type="text" data-type="productName" name="item ' +
count + '" id="itemName_' + count + '" class="form-control
autocomplete_txt" autocomplete="off" required></td>';
html += '<td><select name="codefin ' + count + '" id="codefin_' + count
+ '" class="form-control"><option value="">- CODE -</option><?php
$sel_kat="select * from catfinance where status='Publish'";
$q=mysql_query($sel_kat); while($data_prov=mysql_fetch_array($q)){?>
<option value="<?php echo $data_prov["codecatfinance"] ?>"><?php echo
$data_prov["codecatfinance"] ?></option><?php}?></select>';
html += '<td><input type="number" name="debit ' + count + '" id="debit_'
+ count + '" class="form-control changesNo" autocomplete="off"
onkeypress="return IsNumeric(event);" ondrop="return false;"
onpaste="return false;" required></td>';
html += '<td><input
type="number" name="credit ' + count + '" id="credit_' + count + '"
class="form-control changesNo" autocomplete="off" onkeypress="return
IsNumeric(event);" ondrop="return false;" onpaste="return false;"
required></td>';html += '</tr>';
$('table')['append'](html);
i++;
});
});
</script>
Thank you for your help.. I really appreciate :)
Upvotes: 0
Views: 160
Reputation: 470
Example:
<?php
while ($row = mysql_fetch_array($result))
{
echo "<option value='".$row['path']."'>'".$row['name']."'</option>";
}
?>
$row['path'] // will get the value of the select box value.
$row['name'] // will fetch the list(dropdown)
Upvotes: 1