document.getElementById can not find the element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Moh
    New Member
    • Jul 2007
    • 4

    document.getElementById can not find the element

    Try to use 'document.getEl ementById(("for m11.cl1")' to get commandLink 'cl1'
    Get null return.
    How can I make getElementById to find 'cl1'?

    //---source code:---

    <f:view>
    <afh:html binding="#{back ing_ViewMonthly .html11}" id="html11">
    <afh:head title="Title 1" binding="#{back ing_ViewMonthly .head11}"
    id="head11">
    <link type="text/css" rel="stylesheet " href="../css/jdeveloper.css"/>
    <script type = "text/javascript">
    function doSomething()
    { // Do some javascript stuff here
    alert("Made it to doSomething");
    // get reference to our hidden command link to fire a backing bean method
    var hiddenCommandLi nk = window.document .getElementById ("form11.cl1 ");

    alert("In doSomething, hcl = " + hiddenCommandLi nk);

    // getting back object HTMLFormElement
    if (hiddenCommandL ink )
    {
    hiddenCommandLi nk.fireEvent("o nclick");
    }
    }
    </script>
    </afh:head>
    <afh:body binding="#{back ing_ViewMonthly .body11}" id="body11">
    <af:form binding="#{back ing_ViewMonthly .form11}" id="form11"
    inlineStyle="ba ckground-color:rgb(198,2 14,255);">
    <af:commandLi nk binding="#{back ing_ViewMonthly .cl1}" id = "cl1"
    action="#{backi ng_ViewMonthly. dosomething}"
    partialTriggers ="selectOneChoi ceMm" useWindow="true "
    text="cl1"/>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    you posted in the article-section ... may be a mod will move the thread to the forum.

    to your question:

    Code:
    getElementById()
    uses the id only don't add a formreference to it when 'cl1' is your id then use

    Code:
    getElementById('cl1');
    kind regards

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by gits
      hi ...

      you posted in the article-section ... may be a mod will move the thread to the forum.
      Done !

      Comment

      • Peter Moh
        New Member
        • Jul 2007
        • 4

        #4
        I chage "form11.cl1 " to "cl1". It returns null.

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          when do you call the doSomething-method? when its during load the dom isn't always ready yet ... to reliable get the node ... call it in the onload of the documents body ...

          kind regards

          Comment

          Working...