How to dynamically set the length of an input box

R

Randell_D

Folks,
I have one form with one input box - The length of the input box needs
to be dynamic depending on the users menu option - thus, if they
wanted to add a new currency that my application would support I would
expect them to be fixed with a maximum of 3characters... if they were
to enter a department name, I would want to give them a maximum input
box length of 25characters...

I have created a script that has an onclick/onchange event examining
the length of the input box but this is not preferable - I find
sometimes the third character is included and sometimes its excluded
when I use this method... I'd prefer instead to be able to assign the
fixed length of input box.

can I not do something like

document.forms["form1"].myBox.maxlength=3;

Thanks!
 
B

Bart Van der Donck

Randell_D said:
can I not do something like

document.forms["form1"].myBox.maxlength=3;

Yes, but it is case sensitive:

document.forms["form1"].myBox.maxLength = 3;

If maxLength is lowered, it might be a good idea to set the existing
content of the box to the maximum allowed characters:

document.forms["form1"].myBox.value =
document.forms["form1"].myBox.value.substring(0, 3);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top