I am a newbie and learning new things, I would like them to help me solve my problem, I am working with 3 different radiobuttons and when selecting a certain radio a hidden div appears:
the radiobuttons are called like this:
- monthly_payment: if I select if a hidden div appears with an input text where I add an amount.
- contributions: if I select if a hidden div appears with an input text where I add an amount.
- accounting_payments: if I select if a hidden div appears with an input text where I add an amount.
and obviously I get the total of all the amounts. My problem arises in that if all the radio I put yes and add the amount that I AM and if I hide any div I RESTE the final total.
The hidden div have no problem in showing and hiding, recognize the call, what they do is add and subtract. I think it's something very silly what I can not do, I'm working with javascript and php. Help on how to do it please.
I add code of what I have
<script type="text/javascript">
$(document).ready(function (){
$('input:radio[name=pago_mensual]').change(function (){
if($(this).val()==1){
$("#capa1").show();
}else{
$("#capa1").hide();
}
});
$('input:radio[name=contri]').change(function (){
if($(this).val()==1){
$("#capa2").show();
}else{
$("#capa2").hide();
}
});
$('input:radio[name=conta]').change(function (){
if($(this).val()==1){
$("#capa3").show();
}else{
$("#capa3").hide();
}
});
function resultadoFinal(){
tot=document.getElementById('total');
pag1=document.getElementById('pago1');
pag2=document.getElementById('pago2');
pag3=document.getElementById('pago3');
}
});
</script>
<body >
<form>
<div>
Pago Mensual
<input type="radio" name="pago_mensual" value="1" />Si
<input type="radio" name="pago_mensual" value="0" />No
<div id="capa1" style="display:none;">
Monto Aporte
<input id="pago1" name="pago1" type="text" value="<?php $pago1?>"/>
</div>
</div>
<div>
Contribuciones
<input type="radio" name="contri" value="1" />Si
<input type="radio" name="contri" value="0" />No
<div id="capa2" style="display:none;">
Monto Aporte
<input id="pago2" name="pago2" type="text" value="<?php $pago2?>"/>
</div>
</div>
<div>
Pago Contable
<input type="radio" name="conta" value="1" />Si
<input type="radio" name="conta" value="0" />No
<div id="capa3" style="display:none;">
Monto Aporte
<input id="pago3" name="pago3" type="text" value="<?php $pago3?>"/>
</div>
</div>
<div>
Total: <input id="total" name="total" type="text" value="<?php $total?>"/>
</div>
</form>
</body>