Passing the value of an input

Asked

Viewed 144 times

-3

I am inciante and tho with a doubt that it looks simple but I did not find a response, mto provable that I tho letting a silly thing pass, but I am not managing to pass a value of a text input inside a form to another html file, where is wrong? The variable that is in another file that should save this value is not receiving any object?

    <form action="./teste2.html" method="post">
        <input type="text" id='teste' name='teste'>
        <button type="submit">clique</button>
    </form>

</body> 

------ teste2-----
<script>
```try{
        var b = document.getElementById('teste').value
        window.alert(b)
    }catch(error){
        window.alert(error)
    }

    </script>```

2 answers

0


How you are picking a post variable in a . html file?

I made an example code of how to send and receive by POST.

index php.

<?php
    $teste = $_POST["teste"];

    if (!empty($teste)) {
        echo ("<script>alert('Recebi o valor: $teste')</script>");
    }
?>


<form action="./index.php" method="post">
    <input type="text" id='teste' name='teste'>
    <button type="submit" onClick={mostraValor()}>clique</button>
</form>

<script>
    function mostraValor() {
        var valor = document.getElementById('teste');
        alert("Valor: "+valor.value+" Enviado!");
    }
</script>
  • So I can’t send information to a file in html format? I know I can’t manipulate data in html but in body has js, this information I try to pass does not reach the script? I’m inciante really. Could I get soh in js and html without php msm? vlw by attention//

  • Not Submit/POST, but Voce can pass through the URL. Example: No Index.html window.Location = "index2.html? variable=123";

  • vlw bro, then post Voce uses only to send files that manipulate data. I found a way to use get so how do I get this parameter from the url? sla type take each value that was passed to url and play td in an array

  • Have a friend here from the site who already asks a similar question, at a glance: https://answall.com/questions/75557/passando-values-js-para-outra-pagina-html RememberIf, we have all been beginners at some point and there will always be other times that we will need to learn new technologies and become beginners again. Continue studying and success!

-2

Good night Guito! All right?

Try replacing "submite" with "Submit".

<button type="submit">clique</button>
  • I had seen this little error of posting and forgot to edit dsclp, but the problem still persists

Browser other questions tagged

You are not signed in. Login or sign up in order to post.