1


I have a little problem : I have two functions, one that verify a date in PHP and another that act on div properties in javascript. I would like to call both of them by clicking the button but I can't...
I am surely needing some help.
This is my code :

js

function switch_tab1()
{
    if(document.getElementById("radio_mater_oui").checked==true && (document.getElementById("debut_mater").value == "" || document.getElementById("fin_mater").value == ""))
    {
        document.getElementById("erreur_champs_admin").style.display="";
    }
    else
    {
        tab1_tab2();
    }
}

html button

<button class="btn btn-default" id="change_formulaire" onclick="switch_tab1();<?php Verif_date_admin(); ?>" data-toggle="tab">Valider</button>

php

<?php
function Verif_date_admin()
{
    if(strlen($_SESSION["debut_mater"]) == 10 && strlen($_SESSION["fin_mater"]) == 10)
    {
        // Division des chaînes dans 3 variables chacune afin de reconstituer une chaîne
        // valide pour l'insertion dans la base de données au format anglais
        list($debut_jour,$debut_mois,$debut_annee) = explode('-',$_POST["debut_mater"]);
        list($fin_jour,$fin_mois,$fin_annee) = explode('-',$_POST["fin_mater"]);
        $debut_mater_valide = checkdate($debut_mois,$debut_jour,$debut_annee);
        $fin_mater_valide = checkdate($fin_mois,$fin_jour,$fin_annee);
        // Test de validité des booléens assignés
        if($debut_mater_valide != 1 || $fin_mater_valide != 1)
        {
            echo '<script>document.getElementById("date_format_admin").style.display="";</script>';
        }
        else
        {
            $debut_mater = $debut_annee.'-'.$debut_mois.'-'.$debut_jour;
            $fin_mater = $fin_annee.'-'.$fin_mois.'-'.$fin_jour;
        }
    }
    else
    {
        echo '<script>document.getElementById("date_format_admin").style.display="";</script>';
    }
}
?>

Don't take care of french comments, it is for a rectorship.

0

2 Answers 2

1

Can you please remove <script> tag from you echo statement and try it again.. also you need to use single quotes in next statement

<script>document.getElementById("date_format_admin").style.display="";</script>

when it renders in html it should be like

<button class="btn btn-default" id="change_formulaire" onclick="switch_tab1();

document.getElementById('date_format_admin').style.display=''" data-toggle="tab">Valider</button>
Sign up to request clarification or add additional context in comments.

Comments

0

if you want to execute the PHP function you have to send the data to the server .. PHP function will not execute on user browser so <button class="btn btn-default" id="change_formulaire" onclick="switch_tab1();<?php Verif_date_admin(); ?>" data-toggle="tab">Valider</button> will not work instead of this you execute the PHP function by ajax request in switch_tab1() function and remove PHP function Verif_date_admin() from button click event

2 Comments

I don't know the AJAX world, I only use JQuery from it... But thanks.
you can call the jqery ajax function here is the example (sitepoint.com/use-jquerys-ajax-function)

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.