-1

I need to include a speficif php file if radio is checked

this is my radio :

echo '<input type="radio" name="vue" id="mois" value="mois" onclick="vues()"'; if($mois) {echo "checked"; }

echo '>
            <label for="mois">Mois</label>
      <input type="radio" name="vue" id="semaine" value="semaine" onclick="vues()"'; if($semaine) {echo "checked"; }
echo  '>
            <label for="semaine">Semaine</label>
      <input type="radio" name="vue" id="jour" value="jour" onclick="vues()"'; if($jour) {echo "checked"; }
echo  '>
            <label for="jour">Jour</label>';

I try to do this :

function vues(){
            if($('#mois').is(':checked')){
                  document.getElementById("test").innerHTML = "<?php include '../public/mois.php'; ?>";
            } else if ($('#semaine').is(':checked')){
                  document.getElementById("test").innerHTML = "<?php include '../public/semaine.php'; ?>";
            } else if ($('#jour').is(':checked')){
                  document.getElementById("test").innerHTML = "<?php include '../public/jour.php'; ?>";}
}

But nothing happend..

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
samuel
  • 477
  • 7
  • 21
  • Not quite sure if this is the proper answer however... according to this article you should be using .prop('checked') https://stackoverflow.com/questions/2660323/jquery-checkboxes-and-ischecked – coder42 Apr 23 '19 at 22:00
  • What is in the files that you are trying to include? Just HTML or what? – imvain2 Apr 23 '19 at 22:15

3 Answers3

2

The problem is understanding the difference between client side and server side code. You are mixing the two expecting a result that simply can't happen. However, another solution is to utilize ajax (or jquery load).

function vues(){
            if($('#mois').is(':checked')){
                  $( "#test" ).load( "mois.php" );
            } else if ($('#semaine').is(':checked')){
                  $( "#test" ).load( "semaine.php" );
            } else if ($('#jour').is(':checked')){
                  $( "#test" ).load( "jour.php" );
            }
}
imvain2
  • 15,480
  • 1
  • 16
  • 21
0

you cannot include php files like that through javascript as a php file is parsed once on load.

whatever you are trying to load might be better loading it through an ajax call to a backend action that can then return the contents of one of your files.

pauldrodriguez
  • 480
  • 2
  • 6
  • I'm not quite sure what's in these include files, however if they're just html or they render html and don't conflict with procedures after they're referenced then you can include them like that... – coder42 Apr 23 '19 at 22:13
0

PHP code runs on the server. You can load the render result of an executed PHP, but inject PHP code form the client is not a good practice, even if is possible is a security risk.

regards.