Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: <fieldset> undefined?

  1. #1
    Join Date
    Jan 2007
    Location
    USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default <fieldset> undefined?

    I came across a bug while implementing my field copy script. On a particular form I kept getting an "undefined error". I also noticed that the values in the editable fields were all offset from the way they should have rendered (i.e. the bottom value in the top field). After some head scratching I discovered the deviant. It is the <fieldset></fieldset> tag. Javascript sees it as a form element but doesn't seem to know what it is. The element.type method returns "undefined". I cannot find anything about this in the JS documentation. Anybody know how to deal with this problem?

    If I cannot find a way to trap out the errant object then I'll have no choice but to stop using <fieldset> in my forms.

    Thanks!

    Ruberto

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

    Default

    On what browser?
    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!

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    element.type doesn't say what an element is. typeof element declares what it is, if type == null, it will obviously return an error.
    - Mike

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

    Default

    If one has:
    Code:
    <input type="password" id="pass">
    ... then document.getElementById("pass").type is "password"
    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!

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I think the OP got the wrong impression of the "type" attribute. He/she probably thought it was a method which returned a value of what type the element being tested was. Again, a simple error
    - Mike

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    By the way, there isn't any ways to dynamically change the "type" attribute, that I know of.
    - Mike

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

    Default

    I think the OP got the wrong impression of the "type" attribute. He/she probably thought it was a method which returned a value of what type the element being tested was.
    For form elements, it does.

    Admittedly it's a property, not a method, but I don't think Ruberto has the wrong idea.
    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!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Ruberto View Post
    I came across a bug while implementing my field copy script. On a particular form I kept getting an "undefined error". I also noticed that the values in the editable fields were all offset from the way they should have rendered (i.e. the bottom value in the top field). After some head scratching I discovered the deviant. It is the <fieldset></fieldset> tag. Javascript sees it as a form element but doesn't seem to know what it is. The element.type method returns "undefined". I cannot find anything about this in the JS documentation. Anybody know how to deal with this problem?

    If I cannot find a way to trap out the errant object then I'll have no choice but to stop using <fieldset> in my forms.

    Thanks!

    Ruberto
    Well, you haven't specified where this comes up in the code but, there should be a relatively easy way around it. A fieldset has no type attribute but, some browsers might think that it does. So, you need to find a way to either skip it gracefully or to count it either for for what it is or as just something in the form. For example:

    Code:
    if (element.type||(element.tagName&&element.tagName.toLowerCase()=='fieldset'))
    will return true if the element has a type attribute and/or is a fieldset. While:

    Code:
    if (element.type&&(element.tagName&&element.tagName.toLowerCase()!='fieldset'))
    will return false for a fieldset even if the browser thinks it has a type attribute.

    Other tests can be devised to deal with fieldsets in whatever way you decide that you need to.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    I'd still like to know in what browser(s) this occurs.
    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!

  10. #10
    Join Date
    Jan 2007
    Location
    USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The code is here in another thread:
    http://www.dynamicdrive.com/forums/s...ad.php?t=17078

    You'll need to put the code on a page with a form containing an equal number of hidden and editable form elements. Uncomment the line with //alert(widgetType) which you'll see in the new populateFields() function at the bottom of the posting. You may use this page for a test but it does not have the new populateFields() function.

    http://frankentron.freezope.org/update.html

    I guess it isn't necessary you can use that version the way it is but add some <fieldset> tags and add the line to popup the value of the widgetType variable.

    The <fieldset> tag makes the script break in both Firefox and IE.

    Twey is right I mistakenly wrote method when I should have said property.

    I like John's idea for dealing with this problem, I'm gona give that a try.

    Thanks everyone for the help and instruction. I'll let you know how it turns out later.
    Last edited by Ruberto; 02-03-2007 at 07:29 PM. Reason: added link

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
  •