When returning from settings window, can't see select tag with document.getElementById

I have observed a very strange behaviour in my gadget. I have a select tag in my gadget with the id "Category".

<select id="Category">

...

</select>

In the script for the gadget page, document.getElementById("Category") returns a reference to the element.

If I attempt to call it via the Settings window, in the close event:

categoryelement = System.Gadget.document.getElementById("Category");

then it returns a null reference

Now if I point this to a <span> element called test, alongside the <select> element, then bingo I get the reference.

categoryelement = System.Gadget.document.getElementById("test");

I point it back to Category and it's null. Am I missing something obvious here I've checked the code and I'm not mispelling the ID name, or anything silly like that. document.getElementById also works for anchor and other tags. Can anyone else recreate this behaviour And if so how can I workaround it

Chris



Answer this question

When returning from settings window, can't see select tag with document.getElementById

  • Peter Peng

    >>Try creating the options as below, to see if it makes a difference:

    Unfortunately not. The mystery thickens:

    name = System.Gadget.document.childNodes[0].childNodes[1].childNodes[9].attributes[18].nodeValue;

    alert(name);

    This returns "Category". And childnode[9] is a type 1 element node of type "SELECT"

    name2= System.Gadget.document.getElementById("Category");

    alert(name2);

    This returns null. And yes I have checked the case sensitivity by checking it's "Category" and not "category" and I've tried it both ways.

    Chris


  • HalF

    In the end, I used a workaround, I put an onfocus() on the select and when someone uses it, I dynamically populate it in the gadget, using the settings specified in settings.html.

    Chris


  • Ultrawhack

    I've tried your example both in a Flyout and Settings page and it works okay for me. Does the following code return null as well

    categoryelement = System.Gadget.document.parentWindow.Category;

  • satya999

    Something definitely wrong with either the gadget architecture on my machine, or in general.

    I can locate the element via the old fashion IE4 way document.all:

    category = System.Gadget.document.all[29];

    yet any attempt to set properties of category causes an error, either via the new element, and add, or via options.

    It's definitely in the all collection and the DOM, but any attempt to reference it is doomed. Is it because <select> requires some compulsory attributes I'm using id and have added and taken away name. I wouldn't have thought much else was necessary.

    Chris


  • James Bannan

    Try creating the options as below, to see if it makes a difference:

    var j=0;
    for (i=0; i<xmlControlNameSettings.length; i++)
    {
    if (System.Gadget.Settings.read(xmlControlNameSettingsIdea[ i ]) == true)
    {
    categorytab.options[j] = new Option(xmlTitleSettings[ i ], xmlTitleSettings[ i ]);
    j++;
    }
    }



  • KevinRobinson

    >>Does the following code return null as well

    >>categoryelement = System.Gadget.document.parentWindow.Category;

    Yes it does indeed. I'm at a loss to explain it. I dynamically populate the <select> element with the following code:

    for (i=0; i<xmlControlNameSettings.length; i++)

    {

    if (System.Gadget.Settings.read(xmlControlNameSettingsIdea) == true)

    {

    var newOption = document.createElement("option");

    newOption.text = xmlTitleSettingsIdea;

    newOption.value = xmlTitleSettingsIdea;

    categorytag.add(newOption);

    }

    }

    although it makes not different if I just manually add the Options either.

    It works fine for other input tags, just the select tag seems to cause this behaviour.

    Chris


  • Ronald&amp;#35;2

    Also if I put a couple of selects in the page, System.Gadget.document.getElementsByTagName("select") returns null as well.

    Chris


  • When returning from settings window, can't see select tag with document.getElementById