javascript - Get selected option value which is dynamically generated in a nested loop -
here function working on. need selected option inside while loop. every time trying selected value through select id, it's getting last selected value rest of row.
please me. how can , store full table data.
function generate_schedule($con,$sy,$year_id){ $time = array(1=>'9:30-11:00',2=>'11:30-1:00',3=>'1:30-3:00',4=>'3:15-4:45'); $days = array(1=>'sunday',2=>'monday',3=>'tuesday',4=>'wednesday',5=>'thursday',6=>'friday',7=>'saturday'); $rooms=array(1=>'302',2=>'303',3=>'304',4=>'701',5=>'702',6=>'704',7=>'901',8=>'902',9=>'1402',10=>'1405'); // $yls = mysqli_query($con,"select * year_level_subject year_id='$year_id'"); $yls=mysqli_query($con,"select * year_level_subject yls join subjects s on yls.subj_id=s.subj_id yls.year_id='$year_id'"); $num=mysqli_num_rows($yls); $x = 0; echo '<table class="table table-bordered table-hover" id=" datatable">'; echo '<thead> <tr> <th>time</th> <th>days</th> <th>subject</th> <th>teacher</th> <th>room</th> </tr> </thead>'; while($row=mysqli_fetch_assoc($yls)){ extract($row); echo '<tr>'; echo '<td><select id ="seltime" ><option value=0>select time</option>'; foreach($time $key => $value) { echo '<option value='.$key.'>'; echo $value .'</option>'; } echo '</select></td>'; echo '<td><select class="selday" ><option value=0>select day</option>'; foreach($days $key => $value) { echo '<option value='.$key.'>'; echo $value .'</option>'; } echo '</select></td>'; echo '<td>'.$subj_desc.'</td>'; $teach = mysqli_query($con,"select * teachers"); echo '<td><select id="selteacher" onchange="schedata(this)" > <option value=0>select teacher</option>'; while($row=mysqli_fetch_assoc($teach)){ extract($row); echo '<option value='.$teach_id.'>'.$teach_fname.' '.$teach_mname.' '.$teach_lname.'</option>'; } echo '</select></td>'; echo '</select></td>'; echo '<td><select name ="selroom" ><option value=0>select room</option>'; foreach($rooms $key => $value) { echo '<option value='.$key.'>'; echo $value .'</option>'; } echo '</select></td>'; echo '</tr>'; } echo '</table>';}
you did't give name atribute select element
echo '<td><select id="selteacher" onchange="schedata(this)" >
give name as
echo '<td><select id="selteacher" name="selteacher" onchange="schedata(this)" >
Comments
Post a Comment