Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » Webmasters and Developers » [Javascript] getElementsByName in Internet Explorer broken
Search Topic:
Uniqs:
1622
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
SQL help please »
« How to make a .wmv download instead of stream?  
page: 1 · 2
AuthorAll Replies


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
·AT&T U-Verse

[Javascript] getElementsByName in Internet Explorer broken

ARG! This is driving me up a wall. A call to document.getElementsByName in any other web browser (FireFox, Opera, Chrome, etc.) will work but nooooo, in Internet Explorer it fails miserably. Yes, even in the new IE8 it fails.

Any idea why this thing doesn't work? Any way to fix it?
--
Tom


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD


1 edit
I have never had a problem with this particular DOM method in any browser. Is there an issue in your markup causing IE to burp?

Edit: I mis-read--please see correction: »Re: [Javascript] getElementsByName in Internet Explorer broken


DC DSL
Stays crunchy even in milk
Premium
join:2000-07-30
Washington, DC
·Covad Communications
·Verizon Online DSL

getElementsByName has been deprecated since the days of IE4. I think it only works with a few tags like a and div, and will probably fail on anything added dynamically through DOM. New code should be using the ID attribute and getElementsById. IDs also have to be unique.
--
There is no giant fur-bearing trout.


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
·AT&T U-Verse


3 edits
I use it in the following code...

javascript code:
function SideMenuController() {
var menudiv = document.getElementById('menudiv');
var menucontrollerlink = document.getElementById('menucontroller');

var temp = document.getElementsByName('left');
var contentbox = temp[0];

if (menudiv.style.display == 'none') {
menucontrollerlink.innerHTML = 'Hide Menu';
menucontrollerlink.alt = 'Hide those menus!';
menucontrollerlink.title = 'Hide those menus!';
contentbox.id = 'left';
$('#menudiv').show();

$.post('visitorpreferences.php', {'showmenu': 1});
}
else {
menucontrollerlink.innerHTML = 'Show Menu';
menucontrollerlink.alt = 'I want those menus back!';
menucontrollerlink.title = 'I want those menus back!';
contentbox.id = '';
$('#menudiv').hide();

$.post('visitorpreferences.php', {'showmenu': 0});
}
}

It allows me to hide a portion of the page and extend the left content over to fit the whole box that it's contained within. Essentially I'm taking an object on the DOM named "left" and dynamically taking the ID out of it thus removing the fact that the style attribute is applied.
--
Tom


PingPong

join:2001-02-02
Overhere, HI
clubs:

Only these tags have a NAME attribute according to XHTML 1.0: a, applet, form, frame, iframe, img, and map.

I'm guessing your 'left' elements aren't one of these types, and IE is in fact the only browser following the specs.

Try changing rendering mode to quirks. That should help.


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD

reply to trparky
I deeply apologize--I misread and thought you were discussing getElementsByTagName()

Anyway, name and ID elements are of the same data type in the HTML specs, so why not add an ID of the same value as the NAME to the elements in question.

Furthermore, I see jQuery in use in your code, which makes the entire question moot. I cannot imagine for the life of me why you have the amount of code and DOM usage you have in that method when you have jQuery available...
--
No eat apple, eat cookie. Apple spoil dinner.

My Development Sandbox | LinkedIn Profile


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
·AT&T U-Verse

If you take a look at »www.darkscribes.org/site/index.php and the Javascript library called GlobalJavascript.js located at »www.darkscribes.org/site/GlobalJavascript.js and the DOM elements that I'm working with you'd see what I'm trying to do.

I know that it is a hack-ish way of doing what I'm trying to do but I can see no other way of doing it. To trigger the SideMenuController() function there is an item at the top called "Hide Menu", click it and you can see what the effect is.

If you can give some better way to do what I want, I'm all ears.
--
Tom


PingPong

join:2001-02-02
Overhere, HI
clubs:
If quirks mode doesn't help, try replacing your DIV with an A tag(display:block of course). Also please don't ignore posts containing your sollution. ;D


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
How do you make it go to Quirks mode? Something in a META tag?
--
Tom


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD

reply to trparky
Ok, there are some very non-standard things happening in your page. The way I would tackle this is as follows:


    •Remove the NAME attr from DIV with ID of 'left'
    •Give the DIV with ID of 'left' a CLASS attribute of 'floatingContent'
    •In your CSS which gives the DIV with ID of 'left' its styling , make the CSS selector be '.floatingContent' rather than '#left'
    •Remove the "Hide Menu" link (A) and LI from your navigation list
    •Remove the entire SideMenuController() function (declaration and all)
    •Add the below code:


This will cause the content and menu to show with NO hide link if JS is disabled, and if JS is enabled the hide link will get added with the proper behavior. Other than what I couldn't change in your CSS I tested this fully right on your own site via Firefox with Firebug.

If you take this route, feel free to ask questions as needed to integrate these changes.

Jim

--
No eat apple, eat cookie. Apple spoil dinner.

My Development Sandbox | LinkedIn Profile


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
What? I'm confused about this floating content thing you mentioned. What is that supposed to do?
--
Tom


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD

You're using the ID of the element to select it in your CSS. Then in your JS you're adding/removing the ID to cause the style to change. So in your CSS, instead of

do
--
No eat apple, eat cookie. Apple spoil dinner.

My Development Sandbox | LinkedIn Profile


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
I would add that Javascript you mentioned to my GlobalJavascript.js file?
--
Tom


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD

said by trparky See Profile :

I would add that Javascript you mentioned to my GlobalJavascript.js file?
If that's where you prefer it be located. Anywhere will do.


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
Alright, I think I've done all that you have told me to do but it seems that the Javascript isn't adding that part of the code that is supposed to append that link to the navigation bar.
--
Tom


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD
You have an error in the JS. When you reformatted from my beautiful ( ) formatting to yours, you accidentally removed a close paren on line 309 of GlobalJavascript.js


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
reply to trparky
Nevermind, I had a syntax error in the Javascript. Fixed that and it worked.
--
Tom


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
What's wrong with my choice of formatting the code? LOL
--
Tom


trparky
Bite My Shiny Metal Ass
Premium,MVM
join:2000-05-24
Cleveland, OH
clubs:
·AT&T U-Verse

Anyways, I now have the following code that is working properly.

javascript code:
$(function() {
if ($('#left').hasClass('floatingContent')) $('#navlist').append('<li><a href="#stay" title="Hide those menus!" id="menucontroller">Hide Menu</a></li>');
else $('#navlist').append('<li><a href="#stay" title="Hide those menus!" id="menucontroller">Show Menu</a></li>');

$('#menucontroller').click(function() {
var $menucontroller = $(this);
var $menudiv = $('#menudiv');
var $left = $('#left');

/* Menu is currently showing, hide it */
if ($left.hasClass('floatingContent')) {
$menudiv.hide();
$left.removeClass('floatingContent');
$menucontroller.html('Show Menu');
$.post('visitorpreferences.php', {'showmenu': 0});
}
/* Menu is currently hiding, show it */
else {
$menudiv.show();
$left.addClass('floatingContent');
$menucontroller.html('Hide Menu');
$.post('visitorpreferences.php', {'showmenu': 1});
}

return false;
});
});

--
Tom


JAAulde
yum yum yum yum yum
Premium,MVM
join:2001-05-09
Hagerstown, MD


2 edits
said by trparky See Profile :

What's wrong with my choice of formatting the code? LOL
Oh, well, mine was clearly better. 'Tis an objective fact.
said by trparky See Profile :

Anyways, I now have the following code that is working properly.
Cool, glad to hear it.
--
No eat apple, eat cookie. Apple spoil dinner.

My Development Sandbox | LinkedIn Profile
-
Forums » Tech and Talk » OS and Software » Webmasters and DevelopersSQL help please »
« How to make a .wmv download instead of stream?  
page: 1 · 2


Wednesday, 09-Dec 21:36:32 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10 years online! © 1999-2009 dslreports.com.
page compression OFF
Most commented news this week
· [199] Sprint Sued For Distracted Driving Death
· [107] AT&T Launching New 24 Mbps U-Verse Tier
· [82] 3G Network Test Says AT&T Is Tops
· [72] Mediacom Unveils 105 Mbps Pricing
· [66] Sprint Poised For A Turnaround?
· [63] WPA Cracker: Test WPA-PSK Networks In 20 Minutes
· [56] AT&T Hints At Usage-Based iPhone Data Pricing
· [51] The Future Of Wi-Fi Is Bright
· [47] Site Leaks Yahoo, Verizon Fed Data Share Pricing
· [44] Microwaving Your Innards Is Not 'Extreme'
Most people now reading
· Comcast refused to install 400' feet. [Comcast HSI]
· Is sleeping similar to being dead? [General Questions]
· ICC strats [World of Warcraft]
· Adobe Flash Player version 10.0.42.34 [Security]
· Hot Girl falls face first down stairs [56k Lookout (Broadband Heavy)]
· ICC Strats??? [World of Warcraft]
· Forwarding previous owner's mail [Home Repair & Improvement]
· Windows 7 boot manager editing questions [Microsoft Help]
· RG Firmware update to VDSL2 this morning [AT&T U-verse]