Reputation: 245
I'm working on an asp.net web page, there is a texbox, i want to make sure the text entered is less than 3 characters, the code i wrote is
<input type="text" name="searchcatid" size="15" onblur="test_length(Index.searchchatid)" />
<script>
function test_length(testcontrol) {
var teststring = testcontrol.value;
if (teststring.length >= 3) {
alert("ID must be 3 or fewer characters!");
testcontrol.focus();
}
else {
}
}
</script>
and I get the error "Microsoft JScript runtime error: Unable to get value of the property 'value': object is null or undefined", whenever i enter something, I have no idea what goes wrong, since im really new in asp.net, not even sure my code would actually work, hope someone could help me, thanks a lot
Upvotes: 1
Views: 7064
Reputation: 318488
Pass the input element in a proper way:
<input type="text" name="searchcatid" size="15" onblur="test_length(this);" />
It would be even better if you registered your eventhandlers via JavaScript instead of using inline events.
Upvotes: 1
Reputation: 6996
Is it the problem , please check
name="searchcatid"
Index.searchchatid
The spelling searchcatid
doesn't match
Upvotes: 0