How can I send information from my input automatically by javascript?

3

How can I submit information from my <input /> automatically? I wanted this automatic process to be controlled by the input field size. For example, when the value reaches 8 characters, it automatically sends and moves to another page. In this case my action="sucesso.php" . I know this is possible using javascript but I do not know much about the language.

My code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<?php include 'func.php' ?>
<link href="index.css" rel="stylesheet"></link>
<link href="../Login/css/hover.css"></link>

</head>
<body>

<div class="container">
<form method="Post" action="sucesso.php" name="form">

 <div class="txtbox-container hvr-glow">
   <input type="text" name="txtbox" placeholder="Número do Cartão" autofocus>
 </div>

</form>
</div>
<p><label id="result"></label></p>
<script type="text/javascript">
document.form.submit()

</script>

</body>
</html>

I already have the script in code that automatically sends but does not have that field size control done.

    
asked by anonymous 04.05.2016 / 13:10

2 answers

2

You can use onKeyUp to check how many digits the customer has entered and after 8 digits, submit the form.

It would look like this:

<input id="edValue" type="text" onKeyUp="ValueKeyPress()">
    <script>
    function ValueKeyPress(){
       var edValue = document.getElementById("edValue").value;
       if(edValue.length >= 8){
            //submita o form.
       }     
    }
    <script>

Example: link

    
04.05.2016 / 14:25
0

You should monitor the size of the input value through the onchange event of it. See:

<input type="text" id="campo1" onkeypress="campo1_change(this);" />

<script>
function campo1_change(obj)
{
    if(obj.value.length < 8) return;
    document.forms[0].submit();
}   
</script>
    
04.05.2016 / 13:24