jackpf Posted April 19, 2009 Share Posted April 19, 2009 Has anyone noticed how IE will also get elements by id whilst using by name? This is infuriating, as IE and Firefox will obviously point to different elements for different indexes of the array of element's names. For example: <div id="something"></div> <div name="something"></div> In Firefox, document.getElementsByName('something')[0] returns the second div. In IE it returns the first. Has anyone found a workaround or anything? I mean...IE sucks...but this is just stupid. There is a distinct difference between name and id. I hate IE... Regards, Jack. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 19, 2009 Share Posted April 19, 2009 http://www.quirksmode.org/js/detect.html could use a browser detect like above and if it detects IE to render the first div else render the second. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 suppose you could turn around and check if the id attribute exists Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Well, at the moment I check to see if the attribute's value is undefined. If so, it moves on to the next one. But...this is rediculous. Why can't IE differentiate between an ID and a Name? I've noticed that Opera does this as well. Does Opera use IE's javascript engine or something? Firefox and Safari are fine. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 dude, if that was the only thing that IE had different going on than the rest of the world, I'd be a happy camper. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Lol yeah. It just seems like such a stupid thing to do. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 19, 2009 Share Posted April 19, 2009 on scryptic i get "duplicate ID/NAME 'something" whats wrong with changing the name to something else ??? Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Well, I have IDs and Names that all relate to eachother. It just makes it easier for me to remeber what's what when I'm recoding it. I'd rather not change my code just because IE can't execute javascript properly. An ID is an ID, a Name is a Name. How hard can it be? Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 whenever I'm coding html, I always make pretend that id and name are one in the same. So if I do <div id='blah'>..</div> no other tag/element will have 'blah' as an id OR name. So whether something has an id, name or id AND name, it will always be the same thing. like <input id='something' name='something ..> etc... and no other thing on the page will ever have 'something' as an id OR name. That way, I don't have to worry about stuff like this. I don't see how that's any harder to remember than what you are doing. I can understand not wanting to go back and redo your code, but moving forward, if you do that in the first place, then it won't be a problem. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Yeah, I guess. But what I usually do is give a relevant name/id to my forms and their parts. So for example, the form to post on my forum, is something like this: <form id="post" action="..." method="post"> <textarea name="post"></textarea> <input type="submit" name="submit" /> </form> It just makes sense that way. I often use javascript on my forms, so the form id allows me to do that, and obviously I need the names for PHP. I guess it's preference really. Either way, IE is still doing it wrong though Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 hmm...well tbh I think you should be using better naming conventions. For instance, if the form was a "contact us" form, I would do this: <form id="form_contactUs" name="form_contactUs" action="..." method="post"> <textarea id="form_contactUs_message" name="form_contactUs_message"></textarea> <input type="submit" name="form_contactUs_submit" id="form_contactUs_submt" /> </form> Now, whether I would actually have id AND name in all of those depends on my coding needs, but regardless of whether I do or not, I will not have any other tag/element use those names/ids. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Meh...long names though And as I understand it the use of the name attribute in a form is decpricated. Ahh well, my javascript is working now anyway; just a bit of a pain that I have to check each element to see if it exists because of IE. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 long names, yes, but it's not like your processor is really suffering from it, and better organization makes all the difference in the world when trying to debug or edit/modify later, especially when it's not you that's the one doing it. Good programmers do not just think in the present. They think about the future, too. I spend all day wading through other people's shit, wishing that they would have just put the extra 10 seconds worth of effort it takes to do basic shit, like name stuff better, indent, comment, etc... Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 I personally find my own method more organisational, but obviously that's because it's what I've always used. Probably the same for you. And yeah...but I doubt my site's going to get big enough to have other people working on it any time soon...lol. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 well, your site is your own little sandbox, though. What if you start taking on clients, writing scripts for them, modifying stuff on their site, etc.. where you may not be the first or last programmer to mess with it? I mean, that's the core reason why people push for standards: so people can be on the same page and know what's going on and follow each other's work. I mean, that is the central theme of this very thread: MS dropping the ball on shit, right? Well, you have to practice what you preach... Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Well yeah, but to me my method does seem organised. Naming a form and it's elements in a similiar fashion makes sense to me. Ok, this is my exact post form, taken from my script. <?php echo '<span class="action">Post</span> <form id="post" action="'.$_SERVER['REQUEST_URI'].'" method="post"><div> <textarea class="post" name="post" onkeydown="return tab(this, event);"></textarea><br /><br /> <input type="button" class="post" value="Preview" onclick="AJAX(\'post\');" /><input type="submit" name="submit" class="post" value="Post" /> '.parse_display().' <div id="ajax"></div> </div></form>'; ?> To me, this seems organised. But IE has trouble with my AJAX() function, which uses getElementsByName(). It picks up the form as the first element. As there is only one element actually named "post", I should be able to use [0] as the correct index, but this doesn't work for IE. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Hmm...think I just found a bug in smf. You can't put [ 0 ] (without spaces) ina post. It'll just cut it out. Or atleast, I can't. How odd. So yeah, my last post should have that in. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 lol dunno what to tell you man. Fine and dandy if it makes sense to you, but it obviously causes issues. Quote Link to comment Share on other sites More sharing options...
jackpf Posted April 19, 2009 Author Share Posted April 19, 2009 Lol yeah, I do see your point. Thanks for your help. Cba on changing it all though. Besides, it's IE's issues. Don't really care tbh; I never use it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.