0
Good morning, I need to do the following: The user types some text in an input and this text is not lost if he changes pages. This input has no Submit button. How can I do this? It has BD-free input?
0
Good morning, I need to do the following: The user types some text in an input and this text is not lost if he changes pages. This input has no Submit button. How can I do this? It has BD-free input?
1
You can use jQuery to read the text written in this input: Javascript:
$("#teu_input_id").keyup(function(){
var input = $(this).val();
$.post("/backend.php", {"input": input});
});
PHP:
session_start();
$_SESSION['input'] = filter_var($_POST['input'], FILTER_SANITIZE_STRING);
On the pages where you don’t want to lose the information: PHP
session_start();
$input = filter_var($_SESSION['input'], FILTER_SANITIZE_STRING);
HTML
<input type="text" name="teu_input" id="teu_input_id" value="<?=$_SESSION['input']" />
0
You can save the input value to a variable and then redeem it with some event like onchange
, onclick
and etc.
Functional example:
<html>
<head>
<title>Teste</title>
</head>
<body>
<script type="text/javascript">
function mostrarValor(){
var frm = document.frm;
var val1 = frm.valor1.value;
alert(val1 );
}
</script>
<form name="frm">
<input type="text" name="valor1" size="10" >
<button type="button" onclick="mostrarValor();">Veja os valores</button>
</form>
</body>
</html>
Thanks :D It helped a lot
@Ricardoafonso Always the orders!
Browser other questions tagged html input
You are not signed in. Login or sign up in order to post.
you have to have something that relates the two pages, if you use php you can record in a $_SESSION if you have a js file that this linked the two pages can put in a global variable
– Gabriel Rodrigues