Onchange + submit
Posté : 09 oct. 2013, 16:41
Bonjour, j'ai un soucis avec le code suivant:
Mes valeurs (selRange1 et selRange2 ) s'actualisent bien comme il faut mais quand je valide ce formulaire, je n'ai aucune trace de $_POST['fam1'] et de $_POST['fam2']. D'après mes recherches (et ce que j'ai compris) Onchange va déjà agir comme un submit mais en direct. Comment réajuster le code pour pouvoir avoir les totaux et pouvoir recuperer les valeurs des variables apres le submit ?
Merci d'avance
Code : Tout sélectionner
<?php
session_start();
echo "<head>
<script type=\"text/javascript\">
function updateTotal(){
//On récupère le total
var total=0;
total += parseInt(document.getElementById('selRange1').innerHTML);
total += parseInt(document.getElementById('selRange2').innerHTML);
//Puis on ajoute dans la case
document.getElementById('case_total').innerHTML=total;
}
</script>
</head>";
if ($_POST['verif'] != 1)
{
echo "<form action=\"mapage.php\" method=\"post\">";
echo "<table cellspacing=\"0\" cellpadding=\"3px\" rules=\"rows\" style=\"border:solid 1px #777777; border-collapse:collapse; font-family:verdana; font-size:11px; margin-left:auto; margin-right:auto;\">";
echo "<caption>Composition :</caption>";
echo "<tr style=\"background-color:lightgrey;\">";
echo "<th style=\"width:140px;\">Famille 1</th>";
echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam1\" onchange=\"document.getElementById('selRange1').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange1\">0</span> %</th>";
echo "</tr>";
echo "<tr style=\"background-color:lightgrey;\">";
echo "<th style=\"width:140px;\">Famille 2</th>";
echo "<th> <input type=\"range\" style=\"margin-left: 15%; name=\"fam2\" onchange=\"document.getElementById('selRange2').innerHTML = this.value; updateTotal();\" value=\"0\" step=\"5\" max=\"100\" min=\"0\"></input></th>";
echo "<th style=\"width:50px;\"><span style=\"border: 2px solid black; margin-left: 9%;\"><span id=\"selRange2\">0</span> %</th>";
echo "</tr>";
echo "</table>";
echo "<p style=\"width:100px;\">Votre compo est remplie à: <span style=\"border: 2px solid black; margin: 0px 0px 0px 0px;\"><span id=\"case_total\">0</span> %</p>";
echo "<input type=\"hidden\" name=\"verif\" value=\"1\">";
echo "<input type=\"submit\" name=\"submit\" value=\"Valider votre choix\" />";
echo "</form>";
}
else if ($_POST['verif'] == 1)
{
echo 'valeur des compos : 1= '.$_POST['fam1'].' 2= '.$_POST['fam2'].' ';
print_r($_POST);
}
?>Merci d'avance