<script> <?php if($pid>0) { ?>
var counter=<?php echo $rnum ?>; <?php } else { ?>
var counter = 1; <?php } ?>
var limit = 25;
//function addInput()--------
function addInput()
{
var dt=counter+1; dpid="#datepicker1".concat(dt); dp="datepicker1".concat(dt); djid="#datepicker2".concat(dt); dj="datepicker2".concat(dt);
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "<div class='row no-margin' id='row"+dt+"'><div class='col-md-6 input box'><input name='tkid[]' type='hidden' value='0' id='itemid"+dt+"'><select name='item[]' ><option value='' disabled selected required>Deliverables</option><option value='website'>Website</option><option value='app'>Web Application</option><option value='domain'>Domain Registration</option><option value='hosting'>Hosting</option><option value='content'>Content Writing</option><option value='logo'>Logo Creation</option><option value='analytics'>Google Analytics</option></select></div><div class='col-md-6 input box'><select name='assignedto[]'><option value='' disabled selected required>Assigned To</option><option value='value1'> Value1</option><option value='value2'>Value2</option></select></div><div class='col-md-6 input box' id='dynamicInput1'><input type='text' id='".concat(dp).concat("' name='actualtime[]' placeholder='Actual Time Required' value='' required></div><div class='col-md-5 input box' id='dynamicInput1'><input type='text' id='").concat(dj).concat("' name='ddate[]' placeholder='Delivery Date' value='' required></div><div class='col-md-1 input box'><i class='fa fa-times' aria-hidden='true' onclick='deleteinput("+dt+")'></i></div></div>");
dp=document.getElementById('dynamicInput').appendChild(newdiv);
dg=document.getElementById("dynamicInput").style.display="inline-block";
counter++;
document.getElementById("count").value=counter;
$(dpid).datepicker({minDate: new Date(),dateFormat:'yy-mm-dd'});
$(djid).datepicker({minDate: new Date(),dateFormat:'yy-mm-dd'});
}
//data: {'aid':aid},
$.ajax({
url: 'project.php',
type: 'post',
data: 'dcount'+counter,
success: function(output)
{ //$(".container").html(output)
//alert(dt);
//alert('success, server says '+output);
}, error: function()
{
alert('something went wrong, rating failed');
}
});
};
</script>
如何从数据库中获取值到select选项。不是来自上面的代码。这是一个动态添加文本字段。我希望在动态字段中添加到数据库的值。
答案 0 :(得分:0)
你的问题对我来说不是那么清楚
如果您要求使用动态输入添加选择菜单的技术,最好使用ajax
像
AJAX:
$.ajax({
type: 'post',
url: 'list.php',
data: {
list1 :val
},
success: function (response) {
document.getElementById("itemlist").innerHTML=response;
}
});
<强> PHP 强>
<?php
if(isset($_POST['list1']))
{
$state = $_POST['list1'];
$find=mysqli_query($con,"select city from places where state='$state'");
while($row=mysqli_fetch_array($find))
{
echo "<option>".$row['item']."</option>";
}
exit;
}
?>