[Javascript] maxLength question

Edwin Martin edwin at bitstorm.org
Sat May 19 08:23:01 CDT 2007


DeWayne Crenshaw,
> function changeLength()
> {
> if (document.myForm.radioButton[1].checked) {maxLength
> =5}
> else {maxLength =6}
> }
>
> <INPUT TYPE=TEXT NAME="textBox" id="textBox"
> onfocus="changeLength()">
>
> I'm looking for something that will work cross-browser
> and would appreciate any pointers.
>   

1) In the code above, you only set the value of the variable maxLength. 
To set the length of an element, you have to do something like:

document.myForm.myInput.maxlength = 5;

2) Do not use the onfocus eventhandler for this, because it's possible to change the checkbox without the onfocus-handler being called for a second time.

Edwin Martin

-- 
http://www.bitstorm.org/edwin/en/





More information about the Javascript mailing list