PDA

View Full Version : maxlength


danilda
02-14-2003, 08:16 PM
I am trying to change the maxlength of an input text field based on the value of another field. I can get the size property to work, but not the maxlength. Can someone tell me what I am doing wron? Thanks for your help -- dee


JAVASCRIPT CODE:


function sizeit()
{
if(document.form.change.options[document.form.change.selectedIndex].value == "NPIN")
{
document.form.accession.size = 4
document.form.accession.maxlength = 4;
}
if(document.form.change.options[document.form.change.selectedIndex].value == "ASHA")
{
document.form.accession.size = 6
document.form.accession.maxlength = 6;
}
}



HTML CODE:

<select name="change" onChange="return sizeit();">
<option value="1" selected>Please choose a Change Type</option>
<option value="NPIN">NPIN</option>
<option value="ASHA">ASHA</option>
</select

<b>Accession #</b>&nbsp;&nbsp;<input type="text" name="accession" size="6" maxlength="6">

beetle
02-14-2003, 09:15 PM
use the setAttribute() method, and make your life easier with some references!function sizeit( selElem )
{
var f = selElem.form;
var val = selElem.options[selElem.selectedIndex].value;
var a = f.accession;

if( val == "NPIN")
{
a.size = 4
a.setAttribute( "maxlength", 4 );
}
else if( val == "ASHA" )
{
a.size = 6
a.setAttribute( "maxlength", 6 );
}
} and <select name="change" onChange="sizeit(this);">
You don't need the return here, because sizeIt() doesn't return anything.

danilda
02-18-2003, 03:28 PM
Beetle, thanks for the response. The a.size works, but not the maxlength. I am using IE 6, does this make a difference? Do you have any other ideas to change the maxlength? Thanks for your help.

dee

beetle
02-18-2003, 03:57 PM
Oop, the maxlength attribute becomes maxLength as a property!function sizeit( selElem )
{
var f = selElem.form;
var val = selElem.options[selElem.selectedIndex].value;
var a = f.accession;

if( val == "NPIN")
{
a.size = 4;
a.maxLength = 4;
}
else if( val == "ASHA" )
{
a.size = 6;
a.maxLength = 6;
}
} Durn case-sensitivity! :rolleyes:

danilda
02-18-2003, 04:06 PM
Thanks beetle, you are the greatest.

Danilda