Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Moises Luis

Como Utilizar dados de formulário e apresentá-lo em uma tabela ?

Recommended Posts

Sou iniciante em Javascript, desculpem se a pergunta é pobre, mas no momento é a minha grande dificuldade.

A seguir segue o código de um trabalho que preciso apresentar. A definição do trabalho é a seguinte:

 

O aluno informará suas quatro notas, sua freqüência e seu nome e, ao pressionar um botão, o sistema deverá mostrar, abaixo do formulário e na própria página, uma tabela contendo o nome, as quatro notas informadas, a freqüência em percentagem (considere 32 aulas totais), a média do aluno e se este foi ou não aprovado.

 

 

<html>
<head>


	   <h1> SISTEMA DE VERIFICAÇÃO DE APROVAÇÃO  </h1>
		
		<script text="type/javascript">
			function valida(){
								
				   			  if (document.aluno.nome_aluno.value.length <3){
					  alert ("Digite um nome válido")
						document.aluno.nome_aluno.focus();
					  return false;}
				else {
					  aluno.submit();
					   }		
				

				if ((document.aluno.nota1_aluno.value > 10) || (document.aluno.nota1_aluno.value < 0))
				{
					alert (" Nota 1 inválida ")
					document.aluno.nota1_aluno.focus();
					return false;
				}

				if (isNaN(document.aluno.nota1_aluno.value))
				{
					alert ("O campo (Nota1) deve conter apenas numeros!");
					document.aluno.nota1_aluno.focus();
					return false;
				}
				
				if ((document.aluno.nota2_aluno.value > 10) || (document.aluno.nota2_aluno.value < 0))
				{
					alert (" Nota 2 inválida ")
					document.aluno.nota2_aluno.focus();
					return false;
				}

				if (isNaN(document.aluno.nota2_aluno.value))
				{
					alert ("O campo ( Nota2 )deve conter apenas numeros!");
					document.aluno.nota2_aluno.focus();
					return false;
				}

				if ((document.aluno.nota3_aluno.value > 10) || (document.aluno.nota3_aluno.value < 0))
				{
					alert (" Nota 3 inválida ")
					document.aluno.nota3_aluno.focus();
					return false;
				}

				if (isNaN(document.aluno.nota3_aluno.value))
				{
					alert ("O campo ( Nota3 )deve conter apenas numeros!");
					document.aluno.nota3_aluno.focus();
					return false;
				}

				if ((document.aluno.nota4_aluno.value > 10) || (document.aluno.nota4_aluno.value < 0))
				{
					alert (" Nota 4 inválida ")
					document.aluno.nota4_aluno.focus();
					return false;
				}

				if (isNaN(document.aluno.nota4_aluno.value))
				{
					alert ("O campo ( Nota 4 )deve conter apenas numeros!");
					document.aluno.nota4_aluno.focus();
					return false;
				}

				if ((document.aluno.presenca.value > 32) || (document.aluno.presenca.value < 0))
				{
					alert (" Presença Inválida ")
					document.aluno.presenca.focus();
					return false;
				}

				if (isNaN(document.aluno.presenca.value))
				{
					alert ("O campo ( Presença) deve conter apenas numeros!");
					document.aluno.presenca.focus();
					return false;
				}
			
		
			}
		</script>
	


</head>
	
<body>
		<form name="aluno" id="aluno" onsubmit="return valida()" action = "#">
			
			<br>
			<strong> Nome  : </strong>
			<input type="text" id="nome_aluno" name="nome_aluno" maxlength="40"  />

			<br>
			<strong> Nota 1 : </strong>
			<input type="text" id="nota1_aluno" name="nota1_aluno" maxlength="2" size="2" />
			<br>
			<strong> Nota 2 : </strong>
			<input type="text" id="nota2_aluno" name="nota2_aluno" maxlength="2" size="2" />
			<br>
			<strong> Nota 3 : </strong>
			<input type="text" id="nota3_aluno" name="nota3_aluno" maxlength="2" size="2" />
			<br>
			<strong> Nota 4 : </strong>
			<input type="text" id="nota4_aluno" name="nota4_aluno" maxlength="2" size="2" />
			<br>
			<strong> Presença : </strong>
			<input type="text" id="presenca" name="presenca" maxlength="2" size="2" />
			<br>

			<input type="submit" id="enviar" />	
			</form>

<script language ="Javascript">
nome= document.aluno.nome_aluno.value;
nota1= document.aluno.nota1_aluno.value;
nota2= document.aluno.nota2_aluno.value;
nota3= document.aluno.nota3_aluno.value;
nota4= document.aluno.nota4_aluno.value;
presenca= document.aluno.presenca.value;

media = (nota1 + nota2 + nota3 + nota4)/4;
presenca = (32 * presenca)/10;	

			   if (presenca >= 75) {
				  if (media >= 7){ 
						status = "APROVADO, MÉDIA E PRESENÇA";	
							   }else{
										  status = "REPROVADO POR MÉDIA";	   																			  
							  }
	}
	else {						  
						status = "<p>REPROVADO POR FALTAS</P>";	
	}	
	 

</script>


<strong> Nome do Aluno : </strong> <script>document.write( nome);</script>
<table border="1">
<tr><td>NOTA 1</td>
<td>NOTA2</td>
<td>NOTA 3</td>
<td>NOTA 4</td>
<td>PRESENÇA %</td>
<td>RESULTADO</td></tr>


<tr><td><script language ="Javascript">
document.write (nome);
</script>
 </td>

<td><script language ="Javascript">
document.write (nota1);
</script>
 </td>

<td><script language ="Javascript">
document.write (nota2);
</script>
 </td>

<td><script language ="Javascript">
document.write (nota3);
</script>
 </td>

<td><script language ="Javascript">
document.write (nota4);
</script>
 </td>

<td><script language ="Javascript">
document.write (presenca);
</script>
 </td>

<td><script language ="Javascript">
document.write (status);
</script>
 </td>
</tr>

</table>
</body>



</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.