Javascript radio button et addition
Résolu/Fermé
A voir également:
- Javascript radio button et addition
- Formule excel addition - Guide
- Radio française - Télécharger - Médias et Actualité
- Telecharger javascript - Télécharger - Langages
- Horloge radio pilotée ne se met pas à l'heure ✓ - Forum Accessoires & objets connectés
- Power button lockout - Forum Ecran
1 réponse
j'ai trouvé la solution
utiliser champ caché
<head>
<title>Addition</title>
<style>
body{
font-size:10pt;
font-family:Arial;
}
</style>
<script type="text/javascript">
<!--
function Additionner(eltID_1, eltID_2, eltID_Resultat){
var cacher1 = document.getElementById(eltID_1);
var cacher2 = document.getElementById(eltID_2);
var TOTAL = document.getElementById(eltID_Resultat);
var a = parseInt(cacher1.value);
var b = parseInt(cacher2.value);
if (isNaN(a)) { a = 0; }
if (isNaN(b)) { b = 0; }
TOTAL.value=a+b;
}
function recalculer(){
Additionner("cacher1","cacher2","TOTAL");
}
// -->
</script>
</head>
<body>
<form name=form>
<input type="radio" id="option" name="option" value="1" onClick ="document.form.cacher1.value=200;recalculer();">
<input type="radio" id="option" name="option" value="2" onClick ="document.form.cacher1.value=100,recalculer();">
<input type="radio" id="option" name="option" value="3" onClick ="document.form.cacher1.value=100;recalculer();">
<input type=hidden id="cacher1" value="0">
<input type="radio" id="adhesion" name="adhesion" value="150" onClick ="document.form.cacher2.value=150;recalculer();";>
<input type="radio" id="adhesion" name="adhesion" value="30" onClick ="document.form.cacher2.value=30;recalculer();";>
<input type=hidden id="cacher2" value="0">
<input type="text" id="TOTAL" name="TOTAL" size="13" value="0">
</form>
</html>
utiliser champ caché
<head>
<title>Addition</title>
<style>
body{
font-size:10pt;
font-family:Arial;
}
</style>
<script type="text/javascript">
<!--
function Additionner(eltID_1, eltID_2, eltID_Resultat){
var cacher1 = document.getElementById(eltID_1);
var cacher2 = document.getElementById(eltID_2);
var TOTAL = document.getElementById(eltID_Resultat);
var a = parseInt(cacher1.value);
var b = parseInt(cacher2.value);
if (isNaN(a)) { a = 0; }
if (isNaN(b)) { b = 0; }
TOTAL.value=a+b;
}
function recalculer(){
Additionner("cacher1","cacher2","TOTAL");
}
// -->
</script>
</head>
<body>
<form name=form>
<input type="radio" id="option" name="option" value="1" onClick ="document.form.cacher1.value=200;recalculer();">
<input type="radio" id="option" name="option" value="2" onClick ="document.form.cacher1.value=100,recalculer();">
<input type="radio" id="option" name="option" value="3" onClick ="document.form.cacher1.value=100;recalculer();">
<input type=hidden id="cacher1" value="0">
<input type="radio" id="adhesion" name="adhesion" value="150" onClick ="document.form.cacher2.value=150;recalculer();";>
<input type="radio" id="adhesion" name="adhesion" value="30" onClick ="document.form.cacher2.value=30;recalculer();";>
<input type=hidden id="cacher2" value="0">
<input type="text" id="TOTAL" name="TOTAL" size="13" value="0">
</form>
</html>