简体   繁体   中英

Automatically Submit Form If there is Value

I have a problem to store visitor session. But I have an idea to fix this by automatically submit the form input if there is value.

If I use the auto submit with javascript, it will do automatically submit regardless of whether or not an existing value in the input section.

HTML code

    <form id="id_form" action="login.php" method="post">
        Username: <input type="text" name="user" id="user" value="this_value" /><br />
    Password: <input type="password" name="password" id="password" value="this_password" /><br />
    Save password: <input type="checkbox" name="session"/><br />
<input type="submit" value="Submit" />
</form>

JavaScript

<script>
setInterval(function() {submitform();})
{
  document.getElementById("id_form").submit();
}
</script>

Visitors who save password checking section, will immediately submit automatically if a time to visit this page again. How can this work, is there a solution?

Use following JavaScript code:

if (document.getElementById("user").value !== "" && 
    document.getElementById("password").value !== "") {
  document.getElementById("id_form").submit();
}

Place it at the end of your HTML document to make sure the HTML has already loaded.

you can use onchange or onkeyup events so in your input tag when user enters value form submits automatically

for example :

<input onkeyup="sendform(this.value)" type="text" />
<script>
function sendform(inputvalue)
{
// this is the value of input now you can submit your form
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM