Results 1 to 10 of 10

Thread: Form Field Limiter With A Required Input

  1. #1
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form Field Limiter With A Required Input

    1) Script Title: Form Field Limiter

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...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 />
    <script>
    displaylimit("document.webmaster.required-firstname","",5)
    </script>
    </td>

    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

  2. #2
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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.
    DD Admin

  3. #3
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi DD Admin,

    Thank you for your prompt response.

    The link is:

    http://www.todoroffs.com/Contact_Us/..._webmaster.htm

    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

  4. #4
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    <input type="text" name="required-test" id="required-test">
    
    <script>
    displaylimit("","required-test",5)
    </script>
    DD Admin

  5. #5
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey,

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

    Thank you. Best wishes.

    Regards,

    Kurt Todoroff

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:

    http://www.dynamicdrive.com/forums/a...1&d=1202330278
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's basically a rewrite. I think the script at that link doesn't resemble what you originally downloaded any more, either 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.

    ddadmin:
    Code:
    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •