Do not lose the input text when switching pages

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? Can you do without BD?

    
asked by anonymous 14.10.2015 / 13:43

2 answers

0

You can write the value of the input to a variable and then retrieve it with some event such as 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> 
    
14.10.2015 / 13:57
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 pages where you do not want to lose 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']" />
    
14.10.2015 / 14:02