Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
disabling particular date in input box using jquery in php not working

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For jQuery DatePicker, You need to add jQuery UI JS and CSS.

There are two things you need to follow:

  1. You can not directly write var array = <?php $names ?>; in JS as It will give error, You need to do JSON Encode or You need to add it in quote.

For Exmaple: var array = <?php echo json_encode($names); ?> or var array = '<?php echo implode(",",$names); ?>'

  1. One more thing you missed in code is You didn't added echo for PHP variable which you are using in JS.

For Example: Right now your code is var array = <?php $names ?>;, It is without echo so that $name value will not store in JS variable until you echo it.

For more reference see below code:

        <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 }?>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda