Meu código funciona no Mozilla e no IE, mas não roda em nenhuma versão de Google Chrome!

25/09/2015

0

Sou iniciante e desenvolvi uma página simples em html com um css e um javascript vinculado a ela, o código javascript é simplesmente para saber qual option da tag select do html foi selecionada mas não funciona no Google Chrome, já testei em outros computadores e o resultado é o mesmo. O que esqueci de fazer?
No link a baixo, o codigo exibe o numero que foi selecionado no select (mas isso só acontece no Mozilla e no IE).

Testei no windows 7 e 8 com as versões do Google Chrome 45, 46 canary e 47 canary e nenhum resultado.
Testei linha por linha do Javascript e descobri que a function verifica () não está sendo executada no google chorme. Firefox e IE acitaram bem o meu projeto. A unica coisa que funciona é um alert() simples.

[url:descricao=Aqui podem ver o código funcionando no Firefox, mas não roda no Google Chorme]https://jsbin.com/haluxemigi/1/edit?html,js,output[/url]


O html está assim:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Not Run in Chrome?</title>

<!-- chama a minha função armazenada em um arquivo externo chamado arithmetic.js -->
  <script type="text/javascript" src="js/arithmetic.js"></script>

</head>
<body>
  <select>
	<option id="five" onclick="verifica();" value="5">5</option>
	<option id="ten" onclick="verifica();"  value="10">10</option>
	<option id="fifteen" onclick="verifica();" value="15">15</option>
	<option id="twenty" onclick="verifica();"  value="20">20</option>
	<option id="twentyfive" onclick="verifica();" value="25">25</option>
	<option id="thirty" onclick="verifica();"  value="30">30</option>
	<option id="thirtyfive" onclick="verifica();" value="35">35</option>
	<option id="forty" onclick="verifica();" value="40">40</option>
  </select>
</body>
</html>


e o arquivo js está assim:

function verifica() {

//variaveis que vão ser inseridas no array para verificar qual é o numero selecionado

	curso5h=document.getElementById("five").selected;
	curso10h=document.getElementById("ten").selected;
	curso15h=document.getElementById("fifteen").selected;
	curso20h=document.getElementById("twenty").selected;
	curso25h=document.getElementById("twentyfive").selected;
	curso30h=document.getElementById("thirty").selected;
	curso35h=document.getElementById("thirtyfive").selected;
	curso40h=document.getElementById("forty").selected;

//array contendo as variaveis declaradas acima, o numero selecionado corresponde a TRUE na sua respectiva variável e as demais correspondem a False

	array = [curso5h,curso10h,curso15h,curso20h,curso25h,curso30h,curso35h,curso40h];
	a = 0;

//condicional que verifica qual numero foi selecionado
  for ( i = array.length - 1; i >= 0; i--) {
		
		if (array[i] && i == 7) {
			a = document.getElementById("forty").value;
			alert(a);
		} else{
			if (array[i] && i == 6) {
				a = document.getElementById("thirtyfive").value;
				alert(a);
			} else{
				if (array[i] && i == 5) {
					a = document.getElementById("thirty").value;
					alert(a);
				} else{
					if (array[i] && i == 4) {
						a = document.getElementById("twentyfive").value;
						alert(a);
					} else{
						if (array[i] && i == 3) {
							a = document.getElementById("twenty").value;
							alert(a);
						} else{
							if (array[i] && i == 2) {
								a = document.getElementById("fifteen").value;
								alert(a);
							} else{
								if (array[i] && i == 1) {
									a = document.getElementById("ten").value;
									alert(a);
								} else{
									if (array[i] && i === 0) {
										a = document.getElementById("five").value;
										alert(a);
									}
									
								}
							}
						}
					}
				}
			}
		}
	}
}




Me ajudem, não sei onde errei e não encontrei nada que me ajudasse no google.




Obrigado
Marco Aurélio S. Martins
Marco Martins

Marco Martins

Responder

Post mais votado

25/09/2015

Tente adicionando esse trecho de código


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

Marcelo Pastore

Marcelo Pastore
Responder

Mais Posts

25/09/2015

Marco Martins

Marcelo, agradeço muito sua ajuda, mas não obtive resultado.
Responder

25/09/2015

Marcelo Pastore

Vamos lá Marco Aurelio, mais uma tentativa, aqui tem algumas opções do que pode ser feito:

[url]https://productforums.google.com/forum/#!topic/chrome-pt/OrM7VAsT06U[/url]

Informe se deu certo ou não.
Responder

25/09/2015

Marco Martins

Obrigado Marcelo Pastore e Jothaz, topei com um post de outro forum que fala exatamente a a mesma coisa. O código funcionou perfeitamente:

Errado:


// html

<select>
	<option id="five" onclick="verifica();" value="5">5</option>
	<option id="ten" onclick="verifica();"  value="10">10</option>
	<option id="fifteen" onclick="verifica();" value="15">15</option>
	<option id="twenty" onclick="verifica();"  value="20">20</option>
	<option id="twentyfive" onclick="verifica();" value="25">25</option>
	<option id="thirty" onclick="verifica();"  value="30">30</option>
	<option id="thirtyfive" onclick="verifica();" value="35">35</option>
	<option id="forty" onclick="verifica();" value="40">40</option>
  </select>


função apenas para pegar o value (nunca mais faço isso kkkkk)

function verifica() {
	curso5h=document.getElementById("five").selected;
	curso10h=document.getElementById("ten").selected;
	curso15h=document.getElementById("fifteen").selected;
	curso20h=document.getElementById("twenty").selected;
	curso25h=document.getElementById("twentyfive").selected;
	curso30h=document.getElementById("thirty").selected;
	curso35h=document.getElementById("thirtyfive").selected;
	curso40h=document.getElementById("forty").selected;

	array = [curso5h,curso10h,curso15h,curso20h,curso25h,curso30h,curso35h,curso40h];
	a = 0;

//noprotect
  for ( i = array.length - 1; i >= 0; i--) {
		
		if (array[i] && i == 7) {
			a = document.getElementById("forty").value;
			alert(a);
		} else{
			if (array[i] && i == 6) {
				a = document.getElementById("thirtyfive").value;
				alert(a);
			} else{
				if (array[i] && i == 5) {
					a = document.getElementById("thirty").value;
					alert(a);
				} else{
					if (array[i] && i == 4) {
						a = document.getElementById("twentyfive").value;
						alert(a);
					} else{
						if (array[i] && i == 3) {
							a = document.getElementById("twenty").value;
							alert(a);
						} else{
							if (array[i] && i == 2) {
								a = document.getElementById("fifteen").value;
								alert(a);
							} else{
								if (array[i] && i == 1) {
									a = document.getElementById("ten").value;
									alert(a);
								} else{
									if (array[i] && i === 0) {
										a = document.getElementById("five").value;
										alert(a);
									}
									
								}
							}
						}
					}
				}
			}
		}
	}
}



CORRETO (bem menos trabalho ¬¬)

html correto:

<select id="selecao" onchange="verifica();">
	<option value="5">5</option>
	<option value="10">10</option>
	<option value="15">15</option>
	<option value="20">20</option>
	<option value="25">25</option>
	<option value="30">30</option>
	<option value="35">35</option>
        <option value="40">40</option>
</select>


javascript correto

function verifica(){
    var x = document.getElementById("selecao").value;
    alert("O numero selecionado foi: " + x);
}



Valeu o aprendizado
Responder

25/09/2015

Marcelo Pastore

Se eu ajudei realmente, de nada!
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar