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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't let MAXLENGTH work

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
I have this dynamic row which I created. Everything works fine except that MAXLENGTH attribute doesn't work out. Please tell me what I'm missing...

Here's my code:

var td3 = document.createElement("TD")
var newInput3 = document.createElement("INPUT");
newInput3.type= "text";
newInput3.name = "tabHeading_" + rowCtr;
newInput3.size = 100;
newInput3.width = 100;
newInput3.maxlength = 40;
newInput3.className=fieldFormat;
td3.appendChild(newInput3);

Thanks in advance...

 
Only thing I can see is that the l is in lower case.

newInput3.maxLength


--------------------------------
Codito, ergo sum
 
have you tried

newInput3.setAttribute("maxlength",40);

try the javascript forum

forum216
 
Hi simonchristieis! It worked in Netscape but not in IE..!
:( But I'll deal with that myself now. Thanks a lot!!!

 
Try this:

Call
Code:
td3.appendChild(newInput3);
right after calling the createElement statement (so just before the
Code:
type= "text";
statement).

So basically, move it up 6 lines ;o)

Whether it solves the problem or not, I've always thought it proper practice to add the element immediately, before accessing its properties. Sometimes, I've found things don't quite work as expected otherwise!

Hope this helps,
Dan


believedSometimes, you
 
Hi Dan or BillyRay or one-with-spooky-sign!

I did try as you suggested but it didn't work with MAXLENGTH still. But trying what the other guy suggested, I wonder what's the setAttribute equivalent for IE, since it worked in Netscape.

Nevertheless, I agree with your idea that it would be good programming practice to append the object first before putting the attributes. I've always thought it should be the other way around.
 
Ok here's how it all worked! I did append the object first before I put all attributes, like BillyRay suggested. And I changed 'maxlength' to 'maxLength' like GPZCRASHER posted. And my work's done. I must have picked the wrong material source when i thought attributes are not case-sensitive.

Thanks to all!!!!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top