[Javascript] maxLength question

DeWayne Crenshaw decren at yahoo.com
Sun May 20 10:10:02 CDT 2007


--- Edwin Martin <edwin at bitstorm.org> wrote:

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

Thank you for the pointers. As always happens; shortly
after posting my question I arrived at a "simple"
solution. I used a different function for each radio
button.

function zipLengthUSA()
{
x=5
{
document.myForm.tbZip.maxLength=x
}
}

function zipLengthCAN()
{
x=6
{
document.myForm.tbZip.maxLength=x
}
}

<INPUT TYPE=RADIO NAME="rbUScan" id="rbUScan"
type=radio value=1
onclick=zipLengthUSA();ShowSelect(this.value)>
<INPUT TYPE=RADIO NAME="rbUScan" id="rbUScan"
type=radio value=2
onclick=zipLengthCAN();ShowSelect(this.value)>

<INPUT TYPE=TEXT NAME="tbZip" id="tbZip"
onKeyup="autotab(this, document.myForm.tbPhoneArea)">

What I was looking for; 2 radio buttons / 1 for US zip
code (which has 5 digits) / & 1 for Canada (which has
6 digits) then based on that a textBox for the zip
code with a maxLength for whichever one applied.

The ShowSelect is an array for US States & Canada
Provinces.

I needed the onFocus event in another textBox:

<INPUT TYPE=TEXT NAME="tbTotal" id="tbTotal" VALUE=" "
onFocus="parseelement(this)" READONLY>

to trigger a format currency function, and then send
FOCUS to a third textBox.

Anyway, an interesting phenomena using onFocus in this
way is that in IE it worked fine... $ sign + .00 / but
in FireFox I could see the $ + .00 for only a fraction
of a second / I guess it showed up while FOCUS was
active in the box but as soon as focus was lost it
reverted back to just numbers.

This problem was solved by substituting onBlur.

Thanx again,
decren




 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 



More information about the Javascript mailing list