Pessoal,
estou batendo cabeça em um problema (já pesquisei muito e todos os exemplos q vejo estão exatamente igual ao meu código). Vejam abaixo q no meu teste eu simplesmente atribuo um ID a uma tag
, na linha
seguinte chamo uma Function em um String para pegar o conteúdo dessa tag mas o getElementById não
funciona. A variável wM aparece vazia no alert na linha seguinte. Deem uma olhada:
<!DOCTYPE html>
<html lang ="pt-br">
<head>
<title> loginServlet2 </title>
<meta http-equiv = ”Content-Type” content=”text/html; charset=UTF-8”>
<link rel="stylesheet" type="text/css" href="c:/java/html/css/estilo.css"/>
<script type="text/javascript">
function oMsg()
{
var wM = document.getElementById("test1").value;
alert("wM = ", wM);
}
</script>
</head>
<body>
<h2> Test </h2>
<p id="test1">Please enter your username and password</p>
<script>
alert("Before call oMsg");
oMsg();
</script>
</body>
</html>
Podem me ajudar? Grato.