0

I have one date picker and one form

jQuery( "input[name='datepicker']"  ).datepicker({      changeMonth: true,      changeYear: true, dateFormat: "yy-mm-dd", altFormat:"yy-mm-dd",altField:"#stddate"   }); 



          jQuery("#qtr").change(function() {

              var yr=jquery('#yeardate').val();
              var qtr=jquery('#qtr').val();
              if(qtr=='I'){var month=4;}
              else if(qtr=='II'){var month=7;}
              else if(qtr=='III'){var month=10;}
              else{var month=1;}


        jQuery( "input[name='datepicker']").datepicker("setDate", new Date(yr,month,01) );    

          });

Given below is the form

echo'<form id="change_entry" name="change_entry" >';

        echo"<div align='center' id='qtrpanel'>";
        echo 'Please select Year and Quarter </br>';
       $dyear=2014;
    $thisyear=date('Y');
    $diff=$thisyear-$dyear;
    echo '<select name="yeardate" id="yeardate">';
    for ($i=$dyear;$i<=$thisyear;$i++){ echo'<option class="green" value="'.$i.'"'; 
            if ($thisyear==$i) {echo 'selected';}
            echo'>'.$i.'</option>'; }
        echo '</select>';

        echo '<select name="qtr" id="qtr"> <option value="">Select Quarter</option>
      <option value="I">QTR-I</option> <option value="II">QTR-II</option> <option value="III">QTR-III</option> <option value="IV">QTR-IV</option></select></div>';

      echo "<div id='fc' align='center'>Current Quarter Field Control Placed on:<input type='text' id='fc_placement' name='datepicker'/></div></br/>";

       echo "<div id='tldlist' align='center'><table class='wqtable'><tr><th>TLD No</th><th>Location</th><th>Date of Removal</th><th>Dose Rate (mGy/h)</th><th>Lost</th></tr>";



                while($row=mysql_fetch_array($data))
                    { 
                    $rc++;
                    echo "<tr>";
                    echo "<td><input type='text' value='".$row['tldno']."'/></td>";
                    echo "<td>".$row['location']."</td>";

                    echo "<td><input type='text' id='datepicker".$rc. "'name='datepicker'/></td>";
                echo "<td><input type='text' size='5' id='dose".$rc."'  value='".$row2['radn_level']."'/></td>";
                echo "<td><input type='checkbox' id='lost".$rc."'  value='Y'/></td>";

                    echo "</tr>";
                }





      echo " </table></div>";



       echo '<div align="center" >';
       echo '<input id="frmsubmit" type="submit" value="Submit" width="30" />';
       echo '</div>';

     echo '</form>';

I want to change the default date of the datepicker according to the year and quarter selected. But it is not working. What could be the problem?

mansoondreamz
  • 493
  • 1
  • 4
  • 25

1 Answers1

1

Did you check if month and year variables are setting with correct values?

Also, month starts with 0 i.e Jan is represented with 0.

Also, check if you have written the onChange function in document.ready

sravs
  • 330
  • 2
  • 14