Calcular nota e mostrar na tela

10 respostas
S

Tem um código bem simples aqui que calcula a nota de acordo com as opções e em tempo real mostra lá embaixo no campo Nota só que não está funcionando, alguém ajuda?

<html>


<script type="text/javascript">

	
	function calcularNotas(){

		var notaCalculada = 0.0;
		var notaSomatorioProf = 0.0;
		var notaSomatorioMonit = 0.0;
	
		
		 if (document.getElementById('prof_30').checked) notaSomatorioProf = 10;
		 else if (document.getElementById('prof_20').checked) notaSomatorioProf = 9;
		 else if (document.getElementById('prof_15').checked) notaSomatorioProf = 8;
		 else if (document.getElementById('prof_10').checked) notaSomatorioProf = 6;
		 else if (document.getElementById('prof_05').checked) notaSomatorioProf = 5;
		 else if (document.getElementById('prof_00').checked) notaSomatorioProf = 0;
		
		
		 if (document.getElementById('monit_30').checked) notaSomatorio = 4;
		 else if (document.getElementById('monit_20').checked) notaSomatorioMonit = 3;
		 else if (document.getElementById('monit_15').checked) notaSomatorioMonit = 2;
		 else if (document.getElementById('monit_10').checked) notaSomatorioMonit = 1;
		 else if (document.getElementById('monit_05').checked) notaSomatorioMonit = 0.5;
		 else if (document.getElementById('monit_00').checked) notaSomatorioMonit = 0;
		
		 
		 document.getElementById('nota_somatorio').value = notaSomatorioProf + notaSomatorioMonit;
	
		 if ( (notaSomatorioProf + notaSomatorioMonit) > 10) notaCalculada = 10.0;
		 else notaCalculada = notaSomatorioProf + notaSomatorioMonit;
		 
		 document.getElementById('nota_calculada').value = notaCalculada;

	}
		

</script>

<table border="0" width="800">
<tr>
	<td>
		<table align="center" id="tabelaExp" border="1">
			<tr>
				<th align="center">Atividade</th>
				<th width="65"> &gt;=3A</th>
				<th width="65">   2A</th>
				<th width="65"> 1,5A</th>
				<th width="65">   1A</th>
				<th width="65"> 0,5A</th>
				<th width="65">Nenhum</th>
			</tr>

			<tr>
				<td align="left">Professor terceiro grau na &aacute;rea afim</td>
				<td align="center"><input type="radio" name="prof" id="prof_10.0" value="10" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_9.0" value="9" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_8.0" value="8" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_6.0" value="6" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_5.0" value="5" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_0.0" value="0" onchange="calcularNotas()"></td>
			</tr>

			<tr>
				<td align="left">Monitoria</td>
				<td align="center"><input type="radio" name="monit" id="monit_4.0" value="4" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_3.0" value="3" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_2.0" value="2" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_1.0" value="1" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_0.5" value="0.5" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_0.0" value="0" onchange="calcularNotas()"></td>
			</tr>
		</table>
	</td>
</tr>

<tr>
	<td>
	Nota: <input type="text" name="nota" id="nota" readonly="readonly"></input></td></td>
	
</table>
</form>
		
</body>
</html>

10 Respostas

R
document.getElementById('nota_calculada').value = notaCalculada;

O que seria esse nota_calculada ? um campo ? nao estou vendo esse campo no seu form, acho que voce queria dizer que é o campo que recebe as somas certo ? se sim, altere seu input type disso:

Nota: <input type="text" name="nota" id="nota" readonly="readonly"></input></td></td>

para isto

Nota: <input type="text" name="nota" id="nota_calculada" readonly="readonly"></input></td></td>

No id, mude de nota para nota_calculada.

S

rof20004:
document.getElementById('nota_calculada').value = notaCalculada;

O que seria esse nota_calculada ? um campo ? nao estou vendo esse campo no seu form, acho que voce queria dizer que é o campo que recebe as somas certo ? se sim, altere seu input type disso:

Nota: <input type="text" name="nota" id="nota" readonly="readonly"></input></td></td>

para isto

Nota: <input type="text" name="nota" id="nota_calculada" readonly="readonly"></input></td></td>

No id, mude de nota para nota_calculada.

Opa, esse código que botei foi um pouco mais antigo, acabei de vê, esta aleteração já foi feita e mesmo assim não aparece a nota…

S
<html>


<script type="text/javascript">


	function validar() {
		
		/* CODIGO DE EXEMPLO MOSTRANDO A VALIDAÇÃO DE UM INPUT, SELECT E RADIO
		if (!document.getElementById('tipo_inscricao_mestrado').checked &&
			!document.getElementById('tipo_inscricao_doutorado').checked){
			alert("Escolha o tipo de inscrição");
			return false;
		} else if (document.getElementById('nome').value == ""){
			alert("Preencha o Nome");
			return false;
		} else if (document.getElementById('estado_identidade').options[0].selected) {
			alert("Selecione o Estado da identidade");
			return false;
		} 
		return true;
		*/
	}
	
	function calcularNotas(){

		var notaCalculada = 0.0;
		var notaSomatorioProf = 0.0;
		var notaSomatorioMonit = 0.0;
	
		
		 if (document.getElementById('prof_30').checked) notaSomatorioProf = 10;
		 else if (document.getElementById('prof_20').checked) notaSomatorioProf = 9;
		 else if (document.getElementById('prof_15').checked) notaSomatorioProf = 8;
		 else if (document.getElementById('prof_10').checked) notaSomatorioProf = 6;
		 else if (document.getElementById('prof_05').checked) notaSomatorioProf = 5;
		 else if (document.getElementById('prof_00').checked) notaSomatorioProf = 0;
		
		
		 if (document.getElementById('monit_30').checked) notaSomatorio = 4;
		 else if (document.getElementById('monit_20').checked) notaSomatorioMonit = 3;
		 else if (document.getElementById('monit_15').checked) notaSomatorioMonit = 2;
		 else if (document.getElementById('monit_10').checked) notaSomatorioMonit = 1;
		 else if (document.getElementById('monit_05').checked) notaSomatorioMonit = 0.5;
		 else if (document.getElementById('monit_00').checked) notaSomatorioMonit = 0;
		
		 
		 document.getElementById('nota_somatorio').value = notaSomatorioProf + notaSomatorioMonit;
	
		 if ( (notaSomatorioProf + notaSomatorioMonit) > 10) notaCalculada = 10.0;
		 else notaCalculada = notaSomatorioProf + notaSomatorioMonit;
		 
		 document.getElementById('nota_calculada').value = notaCalculada;

	}
		

</script>


<h2>Formul&aacute;rio de Inscri&ccedil;&atilde;o (Experiência Docente)</h2>
<form name="tabelaDocente" action="ExperienciaPDI.jsp" method="post" onsubmit="return validar()">
<table border="0" width="800">
<tr>
	<td>
		<table align="center" id="tabelaExp" border="1">
			<tr>
				<th align="center">Atividade</th>
				<th width="65"> &gt;=3A</th>
				<th width="65">   2A</th>
				<th width="65"> 1,5A</th>
				<th width="65">   1A</th>
				<th width="65"> 0,5A</th>
				<th width="65">Nenhum</th>
			</tr>

			<tr>
				<td align="left">Professor terceiro grau na &aacute;rea afim</td>
				<td align="center"><input type="radio" name="prof" id="prof_10.0" value="10" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_9.0" value="9" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_8.0" value="8" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_6.0" value="6" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_5.0" value="5" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="prof" id="prof_0.0" value="0" onchange="calcularNotas()"></td>
			</tr>

			<tr>
				<td align="left">Monitoria</td>
				<td align="center"><input type="radio" name="monit" id="monit_4.0" value="4" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_3.0" value="3" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_2.0" value="2" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_1.0" value="1" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_0.5" value="0.5" onchange="calcularNotas()"></td>
				<td align="center"><input type="radio" name="monit" id="monit_0.0" value="0" onchange="calcularNotas()"></td>
			</tr>
		</table>
		<center>*A = Anos de Experiência.</center>
	</td>
</tr>

<tr>
	<td>
	NH: <input type="text" name="nota_somatorio" id="nota_somatorio" readonly="readonly"></input></td></td>
	
</table>
</form>
		
</body>
</html>

Está assim e mesmo assim não funciona… Alguma dica?

R

Entao deve ter alguma coisa errada com seu JavaScript, porque era pra funcionar.

R
NH: <input type="text" name="nota_somatorio" id="nota_somatorio" readonly="readonly"></input></td></td>

Mano, presta atencao

La no metodo voce ta setando valor para NOTA_CALCULADA, o id que ta ai é NOTA_SOMATORIO…ou seja, ta errado, deixa os 2 com o mesmo nome.

S

rof20004:
NH: <input type="text" name="nota_somatorio" id="nota_somatorio" readonly="readonly"></input></td></td>

Mano, presta atencao

La no metodo voce ta setando valor para NOTA_CALCULADA, o id que ta ai é NOTA_SOMATORIO…ou seja, ta errado, deixa os 2 com o mesmo nome.

Na verdade não, como pode vê o calcularNotas() seta tanto a variável nota_calculada como nota_somatorio mais acima…

R

hehehe, desculpa, agora que vi, voce tambem seta nota_somatorio…entao realmente verifique seu JavaScript, verifique os import dele e tudo mais.

S

tranquilo :smiley:
Nossa, já fiz de tudo aqui e não acho esse problema.

R

[quote]
else if (document.getElementById('prof_20').checked) notaSomatorioProf = 9;
[code]

nao vi nenhuma referencia ao prof_20 nos seus campos.

Revisa todo seu codigo, acho que tambem pode ser erro de nome de variaveis.

Abraços.

S

Isso, achei o erro :smiley:
Valeu

Criado 22 de outubro de 2012
Ultima resposta 22 de out. de 2012
Respostas 10
Participantes 2