-1
I want to receive value from a Variable coming from a form, and that this variable appears in alert on another page.
My code is simple but not working.
First the Index code
<head>
<title>Formulário para gerar variável</title>
<script language="text/JavaScript" src="newtag.js"></script>
</head>
<body>
<form method="post" action="_log.html">
Digite seu nome:<br/>
<input type="text" name="texto" id="txt"/>
<input type="submit" value="Enviar" onclick="advice001()" />
</form>
</body>
</html>
Javascript code (separate code)
var texto = document.getElementById("txt");
function advice001(){
alert("Seu texto",texto);
}
And finally, the result to be visible in the Alert bar
<html>
<head>
<script language="JavaScript" src="newtag.js"></script>
<title>Resultado</title>
</head>
<body>
<form>
<input type="button" value="Aperte aqui para ver seu nome" onclick="advice001()"/>
</form>
</body>
</html>
I count on your help! Thank you!
this line is "picking up" only the element, to grab the content use:
var texto = document.getElementById("txt").value
. Second, move this line inside the Function and before thealert
, because you need to see the content when you click. To read another page, search for method "GET" and "query string"– Ricardo Pontual
Hello. Trying to Insert into Function, does not activate Alert and also var text = Document.getElementById("txt"). value is not receiving.
– Digital Woits