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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| window.addEventListener("load", function(event) {
/*Création du titre*/
var titre=document.createElement('div');
titre.innerHTML='Convertisseur de note musicale ';
document.body.appendChild(titre);
/*Création du bouton Notation*/
var buttonNotation=document.createElement('button');
buttonNotation.value="Notation";
buttonNotation.name="Notation";
buttonNotation.innerHTML="Notation";
titre.appendChild(buttonNotation);
/*Création du tableau de correspondance*/
note={'Choisir...':' ','Do':'C','Ré':'D','Mi':'E','Fa':'F','Sol':'G','La':'A','Si':'B'};
/*Création et apparition du bouton Close*/
var buttonClose=document.createElement('button');
buttonClose.value="Close";
buttonClose.name="Close";
buttonClose.innerHTML="Close";
buttonClose.style.display="none";
/*requéte AJAX formulaire*/
buttonNotation.addEventListener('click',function(event){
(function(){
var fonctionFormulaire={
init:function(){
/*Disparition du bouton Notation et apparition du bouton Close*/
buttonNotation.style.display="none";
buttonClose.style.display="block";
titre.appendChild(buttonClose);
event.preventDefault();
var formulaire=document.getElementById('formulaire');
var xmlhttp=new XMLHttpRequest();
xmlhttp.addEventListener('readystatechange',function(event){
if(xmlhttp.readyState==4){
if(xmlhttp.status=="200"){
formulaire.innerHTML=xmlhttp.responseText;
titre.appendChild(formulaire);
}
else
{
alert('error code'+xmlhttp.status+':'+xmlhttp.statusText);
}
}
});
xmlhttp.open("GET","formulaire.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send();
}
}
fonctionFormulaire.init();
})()
});
/*Disparition du formulaire, du bouton close et apparition du bouton notation*/
buttonClose.addEventListener('click',function(event){
formulaire.style.display="none";
buttonNotation.style.display="block";
buttonClose.style.display="none";
titre.appendChild(buttonNotation);
});
/*Réapparition du formulaire aprés un clic sur le bouton Notation*/
buttonNotation.addEventListener('click',function(event){
formulaire.style.display="block";
});
/*Requéte AJAX */
(function(){
var resultat={
init:function(){
var sel=document.getElementById('sel');
sel.addEventListener('change',function(event){
event.preventDefault();
var noteSelected=sel.options[sel.selectedIndex].value;
alert(noteSelected);
var xmlhttp=new XMLHttpRequest();
xmlhttp.addEventListener('readystatechange',function(event){
if(xmlhttp.readyState==4){
if(xmlhttp.status=="200"){
var message=document.getElementById('message');
message.innerHTML=xmlhttp.responseText;
}
else
{
alert('error code'+xmlhttp.status+':'+xmlhttp.statusText);
}
}
});
xmlhttp.open("POST","index.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send("noteSelected="+noteSelected);
});
}
}
resultat.init();
})()
}); |
Partager