View Full Version : Form Field Limiter With A Required Input

Kurt Todoroff
02-18-2009, 03:59 PM
1) Script Title: Form Field Limiter

2) Script URL (on DD): www.dynamicdrive.com/dynamicindex16/limitinput.htm

3) Describe problem: I am unable to make Form Field Limiter work with a required input name. If I remove the "required-" preface and use only "firstname", then the FFL script works. Here is a sample of the code:

<td><input name="required-firstname" type="text" size="35"><br />

I am using Safari and Explorer. Both browsers display the counter and the respective text that follows the counter. However, the counter does not decrement as I type into the field.

Thank you for any and all suggestions.

Kurt Todoroff

02-19-2009, 01:33 AM
Does your form carry a name of "webmaster"? It should based on the code you posted above. If that doesn't work, please post a link to the page on your site that contains the problematic script so we can check it out.

Kurt Todoroff
02-19-2009, 01:39 PM
Hi DD Admin,

Thank you for your prompt response.

The link is:


I have added a second input name using the "Form Field Limiter" code. This input does not use the "required-" value. The "Form Field Limiter" code does work with this input.

Thank you for your assistance.

Kurt Todoroff

02-20-2009, 05:45 AM
I think I see the problem. A hypen (-) within the name attribute is actually illegal, at least when it comes to retrieving the element using JavaScript. Give the field an ID attribute of the same value instead, and have the script use that:

<input type="text" name="required-test" id="required-test">


Kurt Todoroff
02-20-2009, 06:23 PM
Hi DD Admin,

Thank you for your advice. I replaced the hyphen with an underscore. The script works properly. My gratitude.

I noticed an interesting problem that occurs with the script in both my site as well as in the examples that are contained in the Dynamic Drive site. If I type the maximum amount of allowed characters into the input field, then the counter decrements to zero. If I type one more character, then that character appears for a moment and then disappears. However, the counter decrements to negative-one and continues to display this value.

- If I click anywhere outside of this input field, then the counter continues to display negative-one.

- If I click in another input field, then the counter reverts to zero.

- If I click in another input field and then start typing, then the counter reverts to zero.

- If I Tab out of the input field (that is associated with the negative-one counter), then the counter reverts to zero.

The momentarily appearing and disappearing character is a very minor annoyance. However, the negative-one counter value should be addressed. Do you have any suggestions?

Thank you for your assistance.

Kurt Todoroff

02-20-2009, 06:42 PM
I updated this script some time ago, but it doesn't seem to have made it into the DD archives. http://dynamicdrive.com/forums/showthread.php?t=19432

Kurt Todoroff
02-24-2009, 02:29 PM
Hi Twey,

I followed your link, but was unable to locate the code. Can you post it here?

Thank you. Best wishes.


Kurt Todoroff

02-24-2009, 07:15 PM
Ah, indeed! Sorry, I forgot that post linked to my old site. Hm. That is frustrating. I don't seem to have a copy around any more, and the IA doesn't have one either :(

Ah! But there seems to be one here:


Kurt Todoroff
02-25-2009, 12:42 PM
Hi Twey,

I downloaded your code. It does not resemble the originally posted code that I downloaded and am using. Is this a different script?

Thank you.

02-25-2009, 01:09 PM
It's basically a rewrite. I think the script at that link doesn't resemble what you originally downloaded any more, either :p It doesn't use eval() any more, but it does use innerHTML, which isn't much better really (and it's non-standard, too).

Interestingly, on the new version in Fx3, once the end of the input has been reached, it's still possible to type the characters 'l', 'u', 't', 'q', and 'b', although they get removed onkeyup. Other characters don't get entered. I'm quite baffled as to why that's happening.


addEvent:function(targetarr, functionref, tasktype){
if (targetarr.length>0){
var target=targetarr.shift()
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})
this.addEvent(targetarr, functionref, tasktype)
}While I like the style, recursion should really be avoided in Javascript. It's not tail-call optimised, quite slow, and has a fairly low recursion limit (about 1000 times in Spidermonkey, as I recall). It's for this reason that we usually implement map() &c. in terms of a for loop rather than the more natural recursive form.