Commit bf8e2e8d authored by Sylvanus Konan's avatar Sylvanus Konan
Browse files

Merge branch 'Top-k-JS' into 'M2-2022-JS'

Top k js

See merge request !93
parents a824385b 7d9a1d3d
<html>
<body>
<center>
<form name ="topkForm">
<iframe src="https://docs.google.com/forms/d/e/1FAIpQLSdbKDGcVNy8bKfwgsHHepEUOtc705-RGOzvy5ldmC0gQinMMA/viewform?embedded=true" width="700" height="800" frameborder="0" marginheight="0" marginwidth="0">Chargement…</iframe>
</form>
</center>
</body>
</html>
<center>
<h2>Formulaire</h2>
<form name="ClassifyForm">
<fieldset >
<legend>Say if the following todos are professional or personal :</legend>
<table>
<tr>
<th></th>
<th>
Not a priority at all
</th>
<th>
Not a priority
</th>
<th>
Neutral
</th>
<th>
Priority
</th>
<th>
High Priority
</th>
</tr>
<tr>
<td>
First Todo
</td>
<td>
<center>
<input type="radio" name="priority1" id="1" value="Not a priority at all"/>
<label for="1"></label>
</center>
</td>
<td>
<center>
<input type="radio" name="priority1" id="2" value="Not a priority"/>
<label for="2"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority1" id="1" value="Neutral"/>
<label for="3"></label>
</center>
</td>
<td>
<center>
<input type="radio" name="priority1" id="1" value="Priority"/>
<label for="4"></label>
</center>
</td>
<td>
<center>
<input type="radio" name="priority1" id="1" value="High Priority"/>
<label for="5"></label>
</center>
</td>
</tr>
<tr>
<td>
Second Todo
</td>
<td>
<center>
<input type="radio" name="priority2" id="1" value="Not a priority at all"/>
<label for="1"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority2" id="2" value="Not a priority"/>
<label for="2"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority2" id="1" value="Neutral"/>
<label for="3"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority2" id="1" value="Priority"/>
<label for="4"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority2" id="1" value="High Priority"/>
<label for="5"></label>
<center>
</td>
</tr>
<tr>
<td>
Third Todo
</td>
<td>
<center>
<input type="radio" name="priority3" id="1" value="Not a priority at all"/>
<label for="1"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority3" id="2" value="Not a priority"/>
<label for="2"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority3" id="1" value="Neutral"/>
<label for="3"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority3" id="2" value="Priority"/>
<label for="4"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority3" id="1" value="High Priority"/>
<label for="5"></label>
<center>
</td>
</tr>
<tr>
<td>
Fourth Todo
</td>
<td>
<center>
<input type="radio" name="priority4" id="1" value="Not a priority at all"/>
<label for="1"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority4" id="2" value="Not a priority"/>
<label for="2"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority4" id="1" value="Neutral"/>
<label for="3"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority4" id="1" value="Priority"/>
<label for="4"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority4" id="1" value="High Priority"/>
<label for="5"></label>
<center>
</td>
</tr>
<tr>
<td>
Fifth Todo
</td>
<td>
<center>
<input type="radio" name="priority5" id="1" value="Not a priority at all"/>
<label for="1"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority5" id="2" value="Not a priority"/>
<label for="2"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority5" id="1" value="Neutral"/>
<label for="3"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority5" id="1" value="Priority"/>
<label for="4"></label>
<center>
</td>
<td>
<center>
<input type="radio" name="priority5" id="1" value="High Priority"/>
<label for="5"></label>
<center>
</td>
</tr>
</table>
</fieldset>
</form>
<button>Submit</button>
</center>
<h2>Récupération des données du formulaire</h2>
<div id="json">
<span></span>
</div>
<script type="text/javascript">
/* escape = function (str) {
return str
.replace(/[\\]/g, '\\\\')
.replace(/[\"]/g, '\\\"')
.replace(/[\/]/g, '\\/')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t');
};*/
//Le bouton qui va déclencher le script js
let btnSubmit = document.querySelector("button");
btnSubmit.addEventListener("click", () => {
//check si le formulaire a été correctement rempli
//on crée un formData
let fd = new FormData();
//on réccupère les données du formulaire
let priority1 = document.querySelectorAll("input[name = 'priority1']");
for(i=0; i<priority1.length; i++){
if(priority1[i].checked){
Classement1 = priority1[i].value;
}
}
let priority2 = document.querySelectorAll("input[name = 'priority2']");
for(i=0; i<priority2.length; i++){
if(priority2[i].checked){
Classement2 = priority2[i].value;
}
}
let priority3 = document.querySelectorAll("input[name = 'priority3']");
for(i=0; i<priority3.length; i++){
if(priority3[i].checked){
Classement3 = priority3[i].value;
}
}
let priority4 = document.querySelectorAll("input[name = 'priority4']");
for(i=0; i<priority4.length; i++){
if(priority4[i].checked){
Classement4 = priority4[i].value;
}
}
let priority5 = document.querySelectorAll("input[name = 'priority5']");
for(i=0; i<priority5.length; i++){
if(priority5[i].checked){
Classement5 = priority5[i].value;
}
}
//on rempli notre FormData
fd.append("Classement1", Classement1);
fd.append("Classement2", Classement2);
fd.append("Classement3", Classement3);
fd.append("Classement4", Classement4);
fd.append("Classement5", Classement5);
console.log(Array.from(fd));
let JSONString = JSON.stringify(Array.from(fd));
console.log(JSONString);
//let EscapedJSONString = escape(JSONString);
// console.log(EscapedJSONString);
document.querySelector("#json span").textContent = JSONString;
})
</script>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment