We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Updating a row in a table with the value filled out using javascript and php

magnoliar
magnoliar asked
on
Medium Priority
178 Views
Last Modified: 2013-12-12
Hello,

I have a set of four rows each corresponding to a different time and a set of 7 columns which represent the days of week.Every cell has a textfield and a dropdown box associated with it.My code is as follows.

<tr>
<td width="100%" colspan="4">
      <table width="100%">
            <tr>
                  <td>Time</td>
                  <td>Sunday</td>
                  <td>Monday</td>
                  <td>Tuesday</td>
                  <td>Wednesday</td>
                  <td>Thursday</td>
                  <td>Friday</td>
                  <td>Saturday</td>
            </tr>
            
            <?
            //show all service times for the entire day
            $arrTime = array("00:00","00:15","00:30","00:45");
                                    $row = 1;
            foreach( $arrTime as $v )
            {
            ?>
            <tr>
                  <td><?=$v?></td>
                  <td><input type="text" name="time_sunday_<?=$row?>" value="<?=${"time_sunday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_sunday' , this.value );"> <select name="person_sunday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_sunday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_sunday_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
                  
                  <td><input type="text" name="time_monday_<?=$row?>" value="<?=${"time_monday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_monday' , this.value );"> <select name="person_monday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_monday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_monday_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
                  
                  <td><input type="text" name="time_tuesday_<?=$row?>" value="<?=${"time_tuesday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_tuesday' , this.value );"> <select name="person_tuesday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_tuesday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_tuesday_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
                  
                  <td><input type="text" name="time_wednesday_<?=$row?>" value="<?=${"time_wednesday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_wednesday' , this.value );"> <select name="person_wednesday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_wednesday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_wednesdayrov_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
                  
                  <td><input type="text" name="time_thursday_<?=$row?>" value="<?=${"time_thursday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_thursday' , this.value );"> <select name="person_thursday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_thursday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_thursday_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
                  
                  <td><input type="text" name="time_friday_<?=$row?>" value="<?=${"time_friday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_friday' , this.value );"> <select name="person_friday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_friday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_friday_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
                  
                  <td><input type="text" name="time_saturday_<?=$row?>" value="<?=${"time_saturday_" . $row};?>" class="textbox" size="5"  onChange="setAllTimes( <?=$row?> , 'time_saturday' , this.value );"> <select name="person_saturday_<?=$row?>" class="selectbig" onChange="setAllTimes( <?=$row?> , 'person_saturday' , this.value );">
                  <?
                  $arr = array("" , "N" , "P" , "S" , "A" , "O" );
                  foreach( $arr as $v1 )
                  {
                        if( ${"person_saturday_" . $row} == $v1 ){ $s = "SELECTED"; } else { $s = ""; }
                        echo "<option value='$v1' $s>$v1</option>";
                  }
                  ?>
                  </select>                  
                  </td>
            </tr>
            <?
            $row++;
            }
            ?>
            
            
            
      </table>
</td>
</tr>

When the user enter something on row1-col1(which would be sunday at 00:15) it should update all the days of the week at 00:15 (monday 00:15 - i.e row1-col2,tuesday 00:15 row1-col3 and so on) with the value in row1-col1.
If they enter row1-col2(monday at 00:15 ) then it should update tuesday through sunday at 00:15 hours.
In the case when they are updating tuesday at 00:15 hrs(row1-col3),and wednesday 00:15 hrs(row1-col4) is already filled out then row1-col4 should not be update and it should continue with ro1-col5.
I am not sure about how to go on to write the setAllTimes function.

<script language="javascript">

function setAllTimes( rownum, dayofweekfield, valueoffield )
{
                  
}


//-->
</script>

Any help will be greatly appreciated.
Thanks
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Hmm... Can you step back from the technical details of this question and tell us what you are trying to achieve, just in plain language?  Is it a scheduling application?
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
You can install and run the example from Proculopsis -- it works exactly as the author described (even if the description showed little consolidation of thought).
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Yep, it was a good solution!  Thanks, ~Ray
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.