2
My first problem is that I have a select id "T4" which is multiplied by the dial input so far everything well works but I have to limit the result according to the value of select for example if I select 0.50 and enter in the input any number that result can not exceed 2.00 as well as 0.25 can not exceed 1.00 and 0.20 exceed 0.80.
My second problem is to make appear in the input id "total1a" the result of the sum between the fields dial1a until dial7a as they appear.
Follow my code below:
<script src="js/jquery-1.7.1.js"></script>
<script language="javascript">
$(window).load(function(){
// Somente numeros
$('.nr').keyup(function() {
var valor = $(this).val().replace(/[^0-9]+/g,'');
$(this).val(valor);
});
$("#disc1a").keyup(function(){
var quantidade = $(this).val();
var valor = $("#t1").val();
var soma = "";
if ((quantidade != "") && (valor != "")){
soma = (parseFloat(valor) * parseInt(quantidade));
if(isNaN(soma)){
soma = "";
}else{
soma = soma.toFixed(2);
}
}
$("#promo1a").val(soma);
});
$("#disc2a").keyup(function(){
var quantidade = $(this).val();
var valor = $("#t2").val();
var soma = "";
if ((quantidade != "") && (valor != "")){
soma = (parseFloat(valor) * parseInt(quantidade));
if(isNaN(soma)){
soma = "";
}else{
soma = soma.toFixed(2);
}
}
$("#promo2a").val(soma);
});
$("#disc3a").keyup(function(){
var quantidade = $(this).val();
var valor = $("#t3").val();
var soma = "";
if ((quantidade != "") && (valor != "")){
soma = (parseFloat(valor) * parseInt(quantidade));
if(isNaN(soma)){
soma = "";
} if ((soma < "1.50")){
soma = soma.toFixed(2);
}else{
soma = "1.50";
}
}
$("#promo3a").val(soma);
});
$("#t4").change(function(){
var quantidade = $(this).val();
var valor = $("#disc4a").val();
var soma = "";
if ((quantidade != "") && (valor != "")){
soma = (parseFloat(quantidade) * parseInt(valor));
if(isNaN(soma)){
soma = "";
}else{
soma = soma.toFixed(2);
}
}
$("#promo4a").val(soma);
});
});
function calcula(){
var valor = 0;
$('.soma').each(function(i){
valor = parseFloat($(this).val()) + valor ;
});
valor = valor.toFixed(2);
$('#total1a').val( valor );
}
</script>
<link href="tema/css/info.css" rel="stylesheet" type="text/css">
<table class='wrapper' width="800" cellspacing='1' cellpadding='2' >
<tr>
<td width="205" colspan="4" rowspan="2" align="center" class="row1">DADOS APURADOS</td>
<td width="56" rowspan="2" align="center" class="row1">VALOR</td>
<td rowspan="2" class="row1" align="center">DISCRIMINAÇÃO</td>
<td colspan="2" class="row1" align="center">SEM/PROM</td>
</tr>
<tr>
<td width="29" class="row2"><input name="sem1" type="text" id="sem1" size="1"></td>
<td width="53" class="row2"><input name="semdt1" type="text" id="semdt1" value="<?php echo date('Y') ?>" size="3"></td>
</tr>
<tr>
<td width="205" rowspan="7" class="row1" align="center">P<br /> O <br />N <br />T <br />O <br />S <br /><br /><br />
P<br />
O<br />
S<br />
I<br />
T<br />
I<br />
V <br />
O<br />
S</td>
<td width="205" rowspan="4" align="center" class="row1">TEMPO<br />DE<br />SERVIÇO</td>
<td colspan="2" class="row3">FUNÇÃO </td>
<td class="row3">
<input name="t1" type="text" disabled="disabled" id="t1" value="0.10" size="5"></td>
<td width="45" class="row3"><input name="disc1a" type="text" id="disc1a" class="nr" size="9"></td>
<td colspan="2" class="row3"><input name="promo1a" type="text" id="promo1a" class="soma" size="12"></td>
</tr>
<tr>
<td colspan="2" class="row2">PERMANÊNCIA </td>
<td class="row2">
<input name="t2" type="text" disabled="disabled" id="t2" value="0.20" size="5"></td>
<td class="row2"><input name="disc2a" type="text" id="disc2a" class="nr" size="9"></td>
<td colspan="2" class="row2"><input name="promo2a" type="text" id="promo2a" class="soma" size="12"></td>
</tr>
<tr>
<td colspan="2" class="row3">INSTRUTOR</td>
<td class="row3"><input name="t3" type="text" disabled="disabled" id="t3" value="0.25" size="5"></td>
<td class="row3"><input name="disc3a" type="text" id="disc3a" class="nr" size="9"></td>
<td colspan="2" class="row3"><span class="row2">
<input name="promo3a" type="text" id="promo3a" class="soma" size="12">
</span></td>
</tr>
<tr>
<td colspan="2" class="row2">FUNÇÃO</td>
<td class="row2"><select name="t4" id="t4">
<option selected="selected">SELECIONE</option>
<option value="0.50">EM 0.50</option>
<option value="0.25">GCG 0.25</option>
<option value="0.20">DIRETORIA 0.20</option>
</select></td>
<td class="row2">
<input name="disc4a" type="text" id="disc4a" class="nr" size="9">
</td>
<td colspan="2" class="row2"><input name="promo4a" type="text" id="promo4a" size="12"></td>
</tr>
<tr>
<td colspan="3" class="row3">APROVEITAMENTO</td>
<td class="row3"><input name="fer" type="text" disabled="disabled" id="fer" value="0.15" size="5"></td>
<td class="row3"><input name="disc5a" type="text" id="disc5a" size="9"></td>
<td colspan="2" class="row3"><span class="row2">
<input name="promo5a" type="text" id="promo5a" size="12">
</span></td>
</tr>
<tr>
<td rowspan="2" class="row1">TRABALHOS</td>
<td colspan="2" class="row2">CATEGORIA "A"</td>
<td class="row2"><input name="tab1" type="text" disabled="disabled" id="tab1" value="0.50" size="5"></td>
<td class="row2"><span class="row3">
<input name="disc6a" type="text" id="disc6a" size="9">
</span></td>
<td colspan="2" class="row2"><input name="promo6a" type="text" id="promo6a" size="12"></td>
</tr>
<tr>
<td colspan="2" class="row3">CATEGORIA "B"</td>
<td class="row3"><input name="tab2" type="text" disabled="disabled" id="tab2" value="0.10" size="5"></td>
<td class="row3"><input name="disc7a" type="text" id="disc7a" size="9"></td>
<td colspan="2" class="row3"><span class="row2">
<input name="promo7a" type="text" id="promo7a" size="12">
</span></td>
</tr>
<tr>
<td colspan="6" class="row3" align="right">(1) SOMA DOS PONTOS POSITIVOS</td>
<td colspan="2" class="row3"><span class="row2">
<input name="total1a" type="text" id="total1a" onkeyup="up(this)" onblur="calcula();" size="12">
</span></td>
</tr>
</table>
made a sample for better visualization of the problem
thank you friend more think the code does not help because the problem is in select that is multiplied by the input that puts the value, it has three values 0.50 that can not exceed 2.00, 0.25 which cannot exceed 1.00 and 0.20 which cannot exceed 0.80 and the totaling function which you modified is not working. The problem with mine is that it only gives the result if I enter and exit the input and I wanted it to be automatic, any more idea?
– opeta
@opeta I still think the answer to the question this there, with a few edits in the code. I will edit it to demonstrate
– kabstergo