Reputation: 119
In this code below first i have used javascript code for dropdown and when i update only the first row gets updated and remaining is not updated.And in next i used the html code it get all the rows updated pls anyone help to fix this issue.The reason i changed from html to js is for auto year.
<script type="text/javascript">
function autoYear() {
var time = new Date();
var year = time.getYear();
if (year < 1900) {
year = year + 1900;
}
var date = year - 1; /*change the '25' to the number of years in the past you want to show */
var future = year + 10; /*change the '10' to the number of years in the future you want to show */
document.writeln ("<form><select id='year_<?php echo $row->id ?>' name='year_<?php echo $row->id ?>' ><option value=\"\"><?php echo $row->year; ?>");
do {
date++;
if (date != <?php echo $row->year; ?>) {
document.write ("<option value=\"" +date+"\">" +date+ "");
}
}
while (date < future);
document.write ("</select></form>");
}
</script>
<script type="text/javascript">
autoYear();
</script>
Html
<select class="inputmedium" name="year_<?php echo $row->id; ?>" id="year_<?php echo $row->id; ?>" value="<?php echo $row->year; ?>">
<?php for($s=0;$s<8;$s++)
{
if($row->year!=null and $row->year==$year_array[$s]){
echo "<option selected value='" .$year_array[$s]. "'>" .$year_array[$s]. "</option>";
}else{
echo "<option value='" .$year_array[$s]. "'>" .$year_array[$s]. "</option>";
}
} ?>
</select>
<?php
$year_array=array();
$year_array[0]="2013";
$year_array[1]="2014";
$year_array[2]="2015";
$year_array[3]="2016";
$year_array[4]="2017";
$year_array[5]="2018";
$year_array[6]="2019";
$year_array[7]="2020";
?>
Upvotes: 0
Views: 141
Reputation: 553
First of all your code modify this line and check
document.writeln ("<form><select id='year_<?php echo $row->id ?>' name='year_<?php echo $row->id ?>' ><option value=\"\"><?php echo $row->year; ?>");
To
document.writeln ("<form><select id='year_<?php echo $row->id ?>' name='year_<?php echo $row->id ?>' ><option value=\"\"><?php echo $row->year; ?></option>");
And
document.write ("<option value=\"" +date+"\">" +date+ "");
To
document.write ("<option value=\"" +date+"\">" +date+ "</option>");
Upvotes: 1