Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the maxlength value of a text box 1

Status
Not open for further replies.

daph

Programmer
Jun 9, 2000
65
0
0
CA
Hi!

I know that I can get the name or the value of a text box in javascript by typing myField.name / myField.value. My question is: Is it possible to have the value of the maxlength of a text box? If so, how can I do that??

Thanks a lot!

daph
 
Try this....

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<script language=&quot;JavaScript&quot;>
function showlength()
{
if (document.myForm.ALotOffText.value.length == 20)
alert(document.myForm.ALotOffText.value.length);
}

function totallength()
{
alert(document.myForm.ALotOffText.value.length);
}
</script>

<form name=&quot;myForm&quot; method=&quot;post&quot;>
<textarea id=&quot;ALotOffText&quot; name=&quot;ALotOffText&quot; style=&quot;width:490px; height:75px;&quot; onkeypress=&quot;showlength()&quot; ondblclick=&quot;javascript: totallength();&quot;></textarea>
</form>

</body>
</html>


Succes
 
For claity, copy and paste this code and you'll see what I mean. Not sure but I think this is what you're looking for.

code
------------
<html>
<!-- Creation date: 11/29/2001 -->
<head>


<title></title>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function a()
{
alert(text.getAttribute('maxlength'));
}
//-->
</SCRIPT>

</head>

<body>
<INPUT TYPE=&quot;text&quot; NAME=&quot;text&quot; maxlength=&quot;20&quot;>
<INPUT TYPE=&quot;submit&quot; onclick= &quot;return a();&quot;>
</body>

</html>
 
<form name=form1>
<input type=text value=&quot;&quot; name=tb1 maxlenght=30>
</form>
<script language=javascript>
alert(document.form1.tb1.maxlenght);
</script>

Sergio M. Netto.
 
Thanks for the response guys!

phpPete's solution worked great. For document.form.field.maxlength, it causes an error saying it's not an object


thanks again!
:)

daph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top