Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

swathip

Programmer
Oct 10, 2009
17
US
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
 
As you have a client-side problem, why not post the client-side code instead of server-side code which only adds an extra layer of obscurity to your problem?

When / if you do, can you use [ignore]
Code:
[/ignore] tags instead of bold / italic / bold italic text to aid legibility?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top