Results 1 to 4 of 4

Thread: MOZILLA: Error: document.getElementById("kmHokRadio") has no properties

  1. #1
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MOZILLA: Error: document.getElementById("kmHokRadio") has no properties

    Hi all,

    the purpose is next:
    you have 2 radiobuttons. depending of what you choose, the precision choices (dropdown) are different. Within the first radiobutton choice, if you fill in the first 2 input boxes, the value is different again than when you fill in all three.
    (you can check the behaviour in IE)

    My little javascript thing works in IE but NOT in Mozilla.

    In Mozilla I get the error:
    Error: document.getElementById("kmHokRadio") has no properties
    Source File: file:///C:/TEMP/InvoerStreepLijst.htm
    Line: 146

    This is the first line of the last JS script underneath the page.

    I hope you see a light where I am in the dark.
    thx for the effort,
    Whiteman


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script language="JavaScript" src="flora.js"></script>
    <script language="JavaScript" type="text/JavaScript">
    <!--
    document.onkeypress = blockKeyPress;
    function setVisibility(divId) {
    document.getElementById('kmHokRaster').style.visibility='hidden';
    document.getElementById('kmHokXY').style.visibility='hidden';
    document.getElementById(divId).style.visibility='visible';
    }
    //-->
    </script>

    <script language="javascript" type="text/javascript">
    <!--
    var aDc = new Array(30);
    var aVc = new Array(30);

    //Initialize pointers
    var nP = 0;
    var Sind = 0;

    var nP = 0;
    var Sind = 0;

    //xy-coord - value = 1
    Sind++;
    aDc[Sind] = new Array("zeker kmhok");
    aVc[Sind] = new Array("1");
    //kmhok - value = 2
    Sind++;
    aDc[Sind] = new Array("voorkeur kmhok","zeker kmhok");
    aVc[Sind] = new Array("4","1");
    //uurhok - value = 4
    Sind++;
    aDc[Sind] = new Array("onzeker uurhok","voorkeur uurhok","zeker uurhok");
    aVc[Sind] = new Array("3","5","2");

    function SelPrecisie(type) {
    document.getElementById("kmHokRadio").value=type;
    nP=0;
    if (document.getElementById("kmHokRadio").value=="xy") nP=1;
    else if (document.getElementById("kaartBlad").value.length > 0 && document.getElementById("uurHok").value.length > 0) {
    nP=3;
    if (document.getElementById("kmHok").value.length > 0) nP=2;
    }
    NewListad = document.getElementById("myprecisie");
    NewListad.options.length = 1;
    if (nP > 0) {
    nen = aDc[nP].length
    for ( i1 = 0; i1 < nen; i1++ ) {NewListad.options[i1 + 1] = new Option(aDc[nP][i1],aVc[nP][i1]);}
    }
    }

    function setPrecisie() {
    document.getElementById("precisie").value=document.getElementById("myprecisie").value;
    document.getElementById("precisieIndex").value=document.getElementById("myprecisie").selectedIndex;
    }
    //-->
    </script>
    </head>

    <body style="margin-left: 0px; margin-right: 0px; margin-top: 0px; margin-bottom: 0px;">

    <table width="760" cellspacing="0" cellpadding="0" align="center" border="0">

    <tr>
    <td>


    <form name="InvoerStreepLijstForm" method="POST" action="/flora/InvoerStreepLijst.do" onsubmit="setPrecisie()">
    <FIELDSET width="100%">
    <LEGEND>Kmhok informatie invoeren:</LEGEND>
    <table width="750">

    <tr>
    <td class="caption_required"><label>Ligging:<span class="required">*</span></label></td>
    <td>
    <table width="100%" cellspacing="0" cellpadding="0">
    <tr>
    <td width="170">
    <input type="radio" name="kmHokRadio" value="raster" checked="checked" onclick="setVisibility('kmHokRaster');SelPrecisie('raster');" class="smallRadio">
    <label>Volgens kaartraster:</label>
    </td>
    <td width="410" rowspan="2" valign="middle">
    <div id="kmHokRaster" style="position:relative;top:0px;visibility:visible;">
    <table width="390" cellspacing="0" cellpadding="0">
    <tr>
    <td width="390">
    <label>Kmhok(Uurhok):</label>
    <input type="text" name="kaartBlad" value="" onchange="SelPrecisie('raster')" style="width:50px">
    &nbsp;-&nbsp;<input type="text" name="uurHok" value="" onchange="SelPrecisie('raster')" style="width:50px">
    &nbsp;(-&nbsp;<input type="text" name="kmHok" value="" onchange="SelPrecisie('raster')" style="width:50px">)
    </td>
    </tr>
    </table>
    </div>
    <div id="kmHokXY" style="position:relative;top:0px;visibility:hidden;">
    <table width="390" cellspacing="0" cellpadding="0">
    <tr>
    <td width="130">
    <label>X:</label>
    <input type="text" name="x" value="" style="width:50px">
    </td>
    <td width="260">
    <label>Y:</label>
    <input type="text" name="y" value="" style="width:50px">
    </td>
    </tr>
    </table>
    </div>
    </td>
    </tr>
    <tr>
    <td>
    <input type="radio" name="kmHokRadio" value="xy" onclick="setVisibility('kmHokXY');SelPrecisie('xy');" class="smallRadio">
    <label>Volgens co&ouml;rdinaten:</label>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td class="caption_required"><label>Precisie:<span class="required">*</span></label></td>
    <td>
    <input type="hidden" name="precisie" value="">
    <input type="hidden" name="precisieIndex" value="">
    <select name="myprecisie" id="Precisie" >
    <option></option>
    </select>
    </td>
    </tr>

    </table>

    </FIELDSET>
    </form>
    </td>
    </tr>
    </table>

    <script language="JavaScript" type="text/JavaScript">
    //This piece is used so the precisieBox is reloaded with previous settings
    document.getElementById("kmHokRadio").value="raster";
    SelPrecisie(document.getElementById("kmHokRadio").value);
    document.getElementById("myprecisie").selectedIndex = document.getElementById("precisieIndex").value;
    </script>
    </body>
    </html>
    Last edited by whiteman; 11-22-2005 at 03:20 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I just noticed that the other day. For some odd reason, IE will "getElementById" even when there is no element with the id attribute set to the given id. In IE, the name attribute seems to be sufficient, at least with some element types. I guess it is a holdover from where document.all would retrieve an element(s) on the basis of their names, tag names or id. In Mozilla, which does it to spec, if there is no element with id="kmHokRadio" set, there is no element by that id, period. I'm not sure if it will mess up other things in your code or not but, where you have name="kmHokRadio" and similar in the HTML section, change it to id="kmHokRadio". Or, put id="kmHokRadio" in there as an attribute, in addition to name="kmHokRadio".
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Or use getElementsByName("kmHokRadio")[0].
    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!

  4. #4
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    @ John

    Thanks a lot ! Your trick did the job perfectly.

    @ Twey

    Also thanks for your solution. I will keep this one on the side when I have a similar problem.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •