After a bit of Javascript help if possible please. I use php to output a foreach loop on a table (example below), so when I hit submit on the values each of the rows are submitted to the database.
However, my problem if this. If you look at the below I use a bit of JS on the <select> box which when selected should automatically populate the corresponding start_time <input> box, however I can’t seem to get it to work? can anyone help
<?php
if (isset($_POST['Submit']))
{
for($i = 0; $i < count($_POST['user_id']); $i++)
{
//Loop through each and insert into DB
//This is not the problem
//And is just an example showing you how it works
}
}
?>
<form method="POST" action="" name="MyForm">
<table class="appointments">
<thead>
<tr>
<th>Photographer</th>
<th>Start Time</th>
<th>Clocking Off</th>
<th>Off</th>
</tr>
</thead>
<tbody>
<tr>
<td style="background:#990000">User Name 1<input type="hidden" name="user_id[]" value="1" />
<input type="text" class="inputbox" value="" name="start_time[]" />
<select name="timequickpick" onchange="window.document.MyForm.start_time[].value = this.options[this.selectedIndex].value";><!--Need to pass this value picked to start_time above-->
<option value="08:00:00">8:00 AM</option>
<option value="09:00:00">9:00 AM</option>
</select>
</td>
<td style="background:#990000">User Name 2<input type="hidden" name="user_id[]" value="2" />
<input type="text" class="inputbox" value="" name="start_time[]" />
<select name="timequickpick" onchange="window.document.MyForm.start_time[].value = this.options[this.selectedIndex].value";><!--Need to pass this value picked to start_time above-->
<option value="08:00:00">8:00 AM</option>
<option value="09:00:00">9:00 AM</option>
</select>
</td>
</tbody>
</table>
<input name="Submit" class="btn" type="Submit" value="Submit" />
</form>
This will do it for you. You need to watch that the names you choose in your forms are all different. Several of them were the same in your original script. This prevents the script and the form from working properly.
[HIGHLIGHT=“”]
<!doctype HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>