Home > Net >  disabling particular date in input box using jquery in php not working
disabling particular date in input box using jquery in php not working

Time:12-24

i have a php website, there is a form which user can submit, i want to disable few dates if they are already present in database, so i did like below:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<input id="niy" name="idate" value=""/>

 <?php
    $queryusersz = "SELECT * FROM invoice";
    $dbz = mysqli_query($con, $queryusersz);
    while($row = mysqli_fetch_array($dbz)) {
   $names[] = $row['idate'];      
    ?>
    
    <script>
    var array = <?php $names ?>;

$('#niy').datepicker({
    language:'TR',
    beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [ array.indexOf(string) == -1 ]
    }
});
    </script>
  <?php }?>

however the input box doesnt show date and neither i get any errors in console, can anyone please help me with this, thanks in advance.

CodePudding user response:

Here are the code, Please check for your refrence:

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet">

    <input id="niy" name="idate" value=""/>

    <?php
        $queryusersz = "SELECT * FROM invoice";
        $dbz = mysqli_query($con, $queryusersz);
    while ($row = mysqli_fetch_array($dbz)) {
        $names[] = $row['idate'];      
        ?>
        
        <script>
        var array = '<?php echo implode(",",$names) ?>';

            $('#niy').datepicker({
                language:'TR',
                beforeShowDay: function(date){
                    var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                    return [ array.indexOf(string) == -1 ]
                }
            });
        </script>
    <?php }?>
  • Related