Reputation: 73
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
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
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
Reputation: 1710
Just change your script with this
$("#idnya").on("input propertychange", function()
{
if($(this).val().length ==10){
$("#max").submit()
}
});
</script>
Upvotes: 0
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