1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
background-color: lightgrey;
width: 50px;
border: 1px solid black;
padding: 0px;
margin: 20px;
}
</style>
</head>
<body>
<?php
include "cnx.php";
$erreur = 0;
if(!empty($_POST["question"]) ){
$sql3=$cnx->prepare("Insert into question (libelleQuestion,type,nbReponse,nbBonneReponse) values(".$_POST["question"].",".$_POST['type'].",".$_POST['nbreponse'].",".$_POST["bonnereponse"].")");
if($sql3->execute())
{
echo"<script><alert>reussi</alert></script>";
// header('location:<a href="http://localhost/ingetis/INGETIS/Projet%20WEB/index.php');" target="_blank">http://localhost/ingetis/INGETIS/Pro...dex.php');</a>
die;
}
else{
echo"<script><alert>rater</alert></script>";
};
};
echo"<form action='' id='form' method='post'>";
echo "<input type='text' value='' name='question'>";
echo "<br>";
echo "<p>type</p>";
echo"<label class='radio-inline' width='200' height='200' style='border:1px solid'>";
echo"<input type='radio'name='type' id='type' value='0' >simple";
echo" </label>";
echo"<label class='radio-inline' width='200' height='200' style='border:1px solid'>";
echo"<input type='radio' id='type' name='type' value='1'>multiple </label>";
echo" <br>";
echo"<p>nombre de reponse</p>";
echo"<select name='nbreponse' class='custom-select custom-select-lg mb-3' id='sel' >";
echo"<option selected name='nbreponse' value='1'>1</option>";
echo"<option name='nbreponse' value='2'>2</option>";
echo"<option name='nbreponse' value='3'>3</option>";
echo" <option name='nbreponse' value='4'>4</option>";
echo"<option name='nbreponse' value='5'>5</option>";
echo "</select>";
echo"<br>";
echo"<div>Reponses</div>";
echo"<table id='target'></table>";
echo"<input type ='submit' name='btnInserer' value='valider'>";
echo" </form>";
?>
<script>
function getRadioVal(form, name) {
var val;
// get list of radio buttons with specified name
var radios = form.elements[name];
// loop through list of radio buttons
for (var i=0, len=radios.length; i<len; i++) {
if ( radios[i].checked ) { // radio checked?
val = radios[i].value; // if so, hold its value in val
break; // and break out of for loop
}
}
return val; // return value of checked radio or undefined if none checked
}
document.getElementById('sel').addEventListener('click',()=> { document.getElementById('target').innerHTML="";
for (let index = 0; index < document.getElementById('sel').value; index++) {
if(getRadioVal(document.getElementById('form'),'type')==0)
{
document.getElementById('target').innerHTML+='<tr><th><input type="text" name="reponse"></th> <th> <input type="radio" name="bonnereponse" > </th></tr>'
}
else{
document.getElementById('target').innerHTML+='<tr><th><input type="text" name="reponse"></th> <th> <input type="checkbox" name="bonnereponse" > </th></tr>'
}
}})
</script>
</body>
</html> |
Partager