Click to See Complete Forum and Search --> : Auto-submitting a form


carl359
01-12-2004, 05:46 AM
This is my first post, but hopefully not my last!

I have a problem and id appreciate any ideas people might have.

I want to write a function that will automatically submit a form when a text field value reaches a certain length. I also want it to validate the text so that it will only submit the form if the field only contains numbers.

I'd appreacite any help anyone can give me to put me on the right track.

Many thanks,
Carl Whittaker

Kor
01-12-2004, 06:20 AM
something like this (further desired changes can be made):


<html>
<head>
<script>
function filter(field) {
var valo = new String();
var which =".0123456789";
var chars = field.value.split("");
var limit = 10;

for (i = 0; i < chars.length; i++) {
if (which.indexOf(chars[i]) != -1)
valo += chars[i];
}

if (field.value != valo)
field.value = valo;
if(chars.length == limit){
alert("you reach the lenght limit, so your form will be submitted");
document.forms[0].submit()
}
}
</script>
</head>
<body>
<form>
<input name="text" type="text" id="text" size="20" onkeyup="filter(this)" onblur="filter(this)">
</form>
</body>
</html>


the characters limit number is set as var=limit (I chose 10, but you may change it)

carl359
01-12-2004, 07:19 AM
That was exactly what i was looking for.

Only one problem. It will only let me type one letter in. Other than that it works fantastically.