I would like to see if you can help me, guide me to solve this problem, I have a gross value and from this I can add or subtract values, depending on the selection I make, I mean, I come with a gross value of 500000, here I can select if by the combobox if I have scholarships, if I have a scholarship I must add the amount that will be added to the total, and the same for extra contributions, if I select if I should add the amount that will be added to the total, I think that it does, but my problem is that if I go back to hide any of the previous div does not perform the subtraction and I do not know what I'm failing, here I leave my code to see if you can help me:
Javascript:
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
function Suma(name){
param=document.getElementById('ingreso').value;
param1=document.getElementById('monto_aporte').value;
if($('#aporteNo').is(':checked')){
document.getElementById('total').value=eval(param);
}else{
document.getElementById('total').value=eval(param)+eval(param1);
}
}
function Resta(name){
param=document.getElementById('ingreso').value;
param1=document.getElementById('monto_aporte').value;
document.getElementById('total').value=eval(param);
}
function SumaS(name){
param=document.getElementById('ingreso').value;
param2=document.getElementById('monto_s').value;
if($('#sNo').is(':selected')){
document.getElementById('total').value=eval(param);
}else{
document.getElementById('total').value=eval(param)+eval(param2);
}
}
function RestaS(name){
param=document.getElementById('ingreso').value;
param2=document.getElementById('monto_s').value;
document.getElementById('total').value=eval(param);
}
$(document).ready(function (){
$('input[name=aporte]').click(function (){
if($(this).val()==1){
$("#monto").fadeIn();
}else{
$("#monto").fadeOut();
}
});
});
function mostrar(id) {
if (id!=8) {
$("#montoS").show();
}
if (id==0 || id==8) {
$("#montoS").hide();
}
}
</script>
HTML:
<table width="534" border="0" cellspacing="3" cellpadding="0">
<tr>
<td width="137" class="label"> </td>
<td width="182"> </td>
<td width="195" class="ejemplos"> </td>
</tr>
<td height="36" class="label">Total Liquido</td>
<td>
<input name="ingreso" type="text" id="ingreso" value="500000" onchange="javascript:Suma();" onKeyPress="return isNumberKey(event)"/>
</td>
<td class="txtAdvertencia"> </td>
</tr>
<tr>
<td class="txtBoldNormal">Tienes beca</td>
<td>
<select name="ts" id="ts" onChange="mostrar(this.value);">
<option value="0">--</option>
<option value="8" id="sSi" <?php if($pdata['ts']=="8") { echo "selected=\"selected\"";}?> onclick="javascript:RestaS();">Ninguno</option>
<option value="9" id="sNo" <?php if($pdata['ts']=="9") { echo "selected=\"selected\"";}?> onclick="javascript:SumaS();">1</option>
<option value="10" id="sNo" <?php if($pdata['ts']=="10"){ echo "selected=\"selected\"";}?> onclick="javascript:SumaS();">2</option>
<option value="11" id="sNo" <?php if($pdata['ts']=="11"){ echo "selected=\"selected\"";}?> onclick="javascript:SumaS();">3 ó más</option>
</select>
</td>
<td > </td>
</tr>
<tr id="montoS" style="display:<?PHP echo ($pdata['ts']==9 || $pdata['ts']==10 || $pdata['ts']==11)?"checked=\"block\"":"none";?>">
<td height="36" class="label">Monto</td>
<td><input id="monto_s" name="monto_s" type="text" value="<?php if($pdata['monto_s']!=""){echo $pdata['monto_s'];}else{echo "0";};?>" onchange="javascript:SumaS();" onKeyPress="return isNumberKey(event)"/>
</td>
<td class="txtAdvertencia"> </td>
</tr>
<tr>
<td class="txtBoldNormal"> </td>
<td> </td>
<td class="txtAdvertencia"> </td>
</tr>
<tr>
<td height="35" class="label">Aportes Extras</td>
<td class="label">
<input type="radio" name="aporte" id="aporteSi" value="1" <?php if($pdata['aporte']=="1"){ echo "checked";}?> onclick="javascript:Suma();"/>Si
<input type="radio" name="aporte" id="aporteNo" value="0" <?php if($pdata['aporte']=="0"){ echo "checked";}?> onclick="javascript:Resta();"/>No
</td>
<td></td>
</tr>
<tr>
<td class="txtBoldNormal"> </td>
<td> </td>
<td class="txtAdvertencia"> </td>
</tr>
<tr id="monto" style="display:<?PHP echo ($pdata['aporte']==1)?"checked=\"block\"":"none";?>">
<td height="36" class="label">Monto Aporte</td>
<td><input id="monto_aporte" name="monto_aporte" type="text" value="<?php if($pdata['monto_aporte']!=""){echo $pdata['monto_aporte'];}else{echo "0";};?>" onchange="javascript:Suma();" onKeyPress="return isNumberKey(event)"/>
</td>
<td> </td>
</tr>
<tr>
<td class="label">INGRESOS TOTALES (ingresos)</td>
<td><span>
<input name="total" type="text" id="total" value="<?php if($pdata['total']!=""){echo $pdata['total'];}else{echo "0";};?>" onchange="javascript:Suma();SumaS();" onKeyPress="return isNumberKey(event)" />
</span></td>
<td> </td>
</tr>
</table>
And before closing the body I call the functions in block js:
<script>
Suma();
SumaS();
</script>