Aditya Rahadian
Aditya Rahadian

Reputation: 73

Javascript auto submit form not work

i have problem with my code.. i want to make it auto submit after fill the text box with length 10 digit of number.

this is my javascript code

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>

    $("#idnya").on("input propertychange", function()
        {
            if($(this).val().length ==15){
            $("#max").submit()
        }
    });

    </script>

</script>

and this's my php code

<?php
include "koneksi.php";

echo"

<body>
    <form id=max name='cingcing' action='lanjut.php' method='POST'>
    <center>

        <table>
        <tr>
            <td colspan=2> <center> id </center> </td>
        </tr>
        <tr>
            <td> id number </td> <td> <input type=password id='idnya' name='idnya2'> </td> 
        </tr>
    </center>
    </form>
</body>
";
?>

Upvotes: 0

Views: 363

Answers (4)

Sagar Pathak
Sagar Pathak

Reputation: 406

A page can't be manipulated safely until the document is "ready." I think you forgot the ready function. And to check the length you can bind keyup event as below.

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#idnya").on("keyup",function(){
                if($(this).val().length == 10){
                    $("#max").submit();
                }
            });
        });
    </script>

Upvotes: 6

Muhammad Ali
Muhammad Ali

Reputation: 2014

JSFIDDLE demo is here make it on keyup or change

  $("#idnya").keyup(function()
    {
        if($(this).val().length ==15){
        $("#max").submit()
    }
  });

// OR USE CHANGE it will run when you focus being away

  $("#idnya").change(function()
    {
        if($(this).val().length ==15){
        $("#max").submit()
    }
  });

Upvotes: 0

sijo vijayan
sijo vijayan

Reputation: 1710

Just change your script with this

$("#idnya").on("input propertychange", function()
    {
        if($(this).val().length ==10){
        $("#max").submit()
    }
});

</script>

Upvotes: 0

Soorajlal K G
Soorajlal K G

Reputation: 786

this might help u

    <?php
    include "koneksi.php";
    echo "
    <html><head></head>
    <body>
        <form id=max name='cingcing' action='lanjut.php' method='POST'>
        <center>

            <table>
            <tr>
                <td colspan=2> <center> id </center> </td>
            </tr>
            <tr>
                <td> id number </td> <td> <input type=password id='idnya' name='idnya2'> </td> 
            </tr>
            </table>
        </center>
        </form>

    </body>
    </html>";
    ?>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>

        $("#idnya").on("input propertychange", function()
        {
            if ($(this).val().length == 15) {
                $("#max").submit()
            }
        });

    </script>

Upvotes: 0

Related Questions