Very good. I know that this is a treated topic, but in my particular case I can not solve it. I have a form that sends multiple rows to a database. What I need is that when filling in one of the fields manually, an entire column of the form is filled in with that value. The form would be something like:
<form role="form" method="post" action="food.php">
<div class="row">
<div class="col-md-3">
<input type="text" id='food' onchange='add();'>
</div>
<div class="row">
<div class="col-xs-12">
<table id="production" class="table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Batch</th>
<th>Tubs</th>
</tr>
</thead>
<tbody>
<?php while ($r=$query1->fetch_array()):?>
<tr>
<td>
<div class="form-group">
<input type="date" class="form-control" value="<?php echo date('Y-m-d'); ?>" name="feeddate[]" required />
</div>
</td>
<td>
<div class="form-group">
<input type="text" class="form-control" value="<?php echo $r["batchnumber"]; ?>" name="batchnumber[]" />
</div>
</td>
<td>
<div class="form-group">
<input type="text" id='showId' class="form-control" name="batchtubs[]" />
</div>
</td>
And to fill in the field automatically I used this:
<script type="text/javascript">
function add()
{ document.getElementById('showId').value=document.getElementById('food').value;
}
</script>
The problem is that I only fill the first row of values, but there are more than 60 (the number is variable, depending on the values that the query brings).
I've tried other functions, like
<script type="text/javascript">
function add()
{
jsvar=document.getElementById('food').value;
document.formname.formvar.value = jsvar;
}
</script>
<input id='food' onchange='add();'>
<form name="formname">
<input name="formvar" value="">
</form>
That I did well doing tests, until I inserted it in the td field of the table, and I no longer returned the values.
I also tried other ideas, but without result:
<form name="form" action="" method="post">
<input type="text" name="subject" id="subject" value="230">
<input type="text" name="new" id="new" value="<?php echo $POST['subject']; ?>">
</form>
I have a pretty clear feeling that I'm making a mess of myself. Any ideas to solve it? Thank you! Alex.