Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-02-2007, 09:43 PM
Ruberto Ruberto is offline
Junior Coders
 
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
Reply With Quote
  #2  
Old 02-02-2007, 09:54 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
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!
Reply With Quote
  #3  
Old 02-02-2007, 09:54 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 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.
Reply With Quote
  #4  
Old 02-02-2007, 10:03 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
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!
Reply With Quote
  #5  
Old 02-02-2007, 10:49 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 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
Reply With Quote
  #6  
Old 02-02-2007, 10:50 PM
mburt's Avatar
mburt mburt is offline
Elite Coders
 
Join Date: Jul 2006
Location: Canada
Posts: 2,507
Thanks: 5
Thanked 22 Times in 22 Posts
Default

By the way, there isn't any ways to dynamically change the "type" attribute, that I know of.
Reply With Quote
  #7  
Old 02-02-2007, 11:56 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
Thanks: 1
Thanked 180 Times in 172 Posts
Blog Entries: 2
Default

Quote:
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!
Reply With Quote
  #8  
Old 02-03-2007, 05:54 AM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,999
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
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.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #9  
Old 02-03-2007, 03:08 PM
Twey's Avatar
Twey Twey is offline
Modtoreador
 
Join Date: Jun 2005
Location: 英国
Posts: 11,933
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!
Reply With Quote
  #10  
Old 02-03-2007, 07:24 PM
Ruberto Ruberto is offline
Junior Coders
 
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
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:27 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.