Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / February 2007



Tip: Looking for answers? Try searching our database.

test overwrite of getElementsByName for IE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tsalm - 24 Feb 2007 00:13 GMT
Hi everybody,

I need to get a element create dynamically by its name. It's ok for
FF, but on IE, getElementsByName return "undefined".
I create this code but not sure that it can work on older IE ....if
someone can test this code on older IE ?
( and in the hope that it can be usefull for others ! )

1- It first create a combobox dynamically and set the NAME attribute
to it.
2- It overwrite the getElementsByName method if the nav is IE
3- If all is ok, it must write the innerHTML code in an alert box

thanks for help,
TSalm

=====Test.html====

<html>
<head></head>
<body></body>
<script language="javascript">

// <<< BEGIN INSERT

 var values = new Array("a","b","c");

    var inputElementName = "SELECT";
    var input = document.createElement(inputElementName);

    input.setAttribute('name', "test.test[0]");

    for (i=0;i<values.length; i++) {
    var option = document.createElement("OPTION");
    option.setAttribute("value",  values[i]);
    option.innerHTML = values[i];
    input.appendChild(option);
    }

    document.body.appendChild(input);
//  END >>>

// <<<
function findElByName(nd,strName) {

    for (i=0;i<nd.childNodes.length;++i) {

   // find it ?
   if (nd.childNodes[i].name==strName) {
     return nd.childNodes[i];
        }

        // childNode ?
        if ((nd.childNodes[i].hasChildNodes()) && (nd.childNodes[i].tagName !
= "OPTION")) {
         val = findEl(nd.childNodes[i],strName);
         if (val) return val;
        }
 }

 return null;

}

if (navigator.appName == "Microsoft Internet Explorer") {
 document.getElementsByName = function(str) {
   o = findElByName(document.body,str);
   if (o) {
     return new Array(o);
   }
   return undefined;
 }
}
// >>>

alert(document.getElementsByName("test.test[0]")[0].innerHTML);

</script>
</html>

====END====
tsalm - 28 Feb 2007 14:58 GMT
Nobody have IE 5 ?

> Hi everybody,
>
[quoted text clipped - 76 lines]
>
> ====END====
Randy Webb - 28 Feb 2007 21:40 GMT
tsalm said the following on 2/28/2007 9:58 AM:
> Nobody have IE 5 ?

Are you kidding? Trying to find an IE5.5 user is hard enough, much less
an IE5 user.

Signature

Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.