samedi 26 août 2017

IF / ELSE comparison with js variable [duplicate]

This question already has an answer here:

I'm trying to run the following code but surely missing something. Regardless the value of the "myPlan" js variable the php echo is always "Something went wrong with the chosenPlan"

    <script type="text/javascript">
    document.write("<b>JAVASCRIPT</b><br>");
    var myPlan = sessionStorage.getItem("plan");
</script>
<?php
    $myPlan = '<script>document.write(myPlan);</script>';

    if($myPlan == 'plan1'){
        echo "Chosen plan is number 1<br>";
    } elseif($myPlan == 'plan2'){
        echo "Chosen plan is number 2<br>";
    } elseif($myPlan == 'plan3'){
        echo "Chosen plan is number 3<br>";
    } else {
        echo "-- Someting went wrong with the chosenPlan --";
    }
?>

Aucun commentaire:

Enregistrer un commentaire