0

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";


?>

1 Answer 1

1

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>");
Sign up to request clarification or add additional context in comments.

1 Comment

the problem is not solved only the first row gets updated remaining row are not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.