The form does not include the element...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    The form does not include the element...

    I am generating a HTML code through AJAX, and setting that HTML into a DIV and the DIV is inside a form. Now the form does not include an element which is being generated through AJAX. But whenever i access that element using ...
    [code=javascript]
    document.getEle mentsByName('el ement_name').le ngth //it returns some value.
    [/code]

    But whenever i trying to access that element using ...
    [code=javascript]
    document.forms['form_name'].elements['element_name'] //it returns undefined.
    [/code]

    This is not working in Mozilla but in IE working. What could be the problem, please help me out !!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Show the code that you're using, what you're returning from the script and the HTML code.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by acoder
      Show the code that you're using, what you're returning from the script and the HTML code.
      The HTML view goes here ....

      [code=HTML]


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <link rel='StyleSheet ' href='./css/style1.css' />

      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Projec t Proposals Delete</title>
      <script language="JavaS cript" src="./build/common.js"></script>
      <script type="text/javascript" language="JavaS cript" src="./build/proposal_delete .js"></script>

      </head>
      <body onload="ajaxFul lDetails('31')" >

      <fieldset>
      <legend>Delet e Proposal </legend>
      <table align="left" cellpadding="5" cellspacing="5" border="0" width="100%">
      <form name="proposal_ delete">
      <tr>
      <td width="10%" align="right">
      <b>Search By</b>
      </td>

      <td>
      <input type="radio" name="propSearc h" value="ByDepart ment" onclick="showTy pe()" > By Department
      <br>
      <input type="radio" name="propSearc h" value="ByPcode" onclick="showTy pe()" > By ProposalCode

      </td>
      <td colspan="1">
      <table border="1" style='border-color:#557CD7' id=display_tab cellspacing=2 cellpadding=4 align="left">
      <tr>
      <th>Total No Of Proposal</th>

      <th>Total No Of Approved Proposal</th>
      <th>Total No Of New Proposal</th>
      </tr>

      <tr>
      <td align="center"> <input type="text" size="10" value="112" readonly> </td>
      <td align="center"> <input type="text" size="10" value="95" readonly></td>
      <td align="center"> <input type="text" size="10" value="17" readonly></td>
      </tr>

      </table>
      </td>
      </tr>
      <tr>
      <td colspan="3">
      <div id="prop_dept" style="display: none">
      <fieldset>
      <legend> Proposal By Department </legend>
      <table align="center">

      <td><b> Department Name</b></td>
      <td>
      <input type="text" name="deptName" size="30" readonly>
      <img src='./html/img/lov.gif' style='width:20 px;height:15px; cursor:pointer' valign='middle' onclick="getDep artment('31')">
      <input type="hidden" name="deptCode" value="">
      </td>
      </table>
      </fieldset>
      </div>

      <div id="prop_date" style="display: none">
      <fieldset>
      <legend>Proposa l Search By Date</legend>

      <table align="center">


      <tr>
      <td >
      <b>From Date</b>
      </td>


      <td>

      <input type="text" name="fromDate" id="fromDate" value="" size="18" readonly />
      <img src='./html/images/calendar.gif' style='width:20 px;height:15px; cursor:pointer' valign='middle' onClick="getDat e('fromDate');" >

      </td>

      <td >
      <b>To Date</b>
      </td>

      <td >

      <input type="text" name="toDate" id="toDate" value="" size="18" readonly />
      <img src='./html/images/calendar.gif' style='width:20 px;height:15px; cursor:pointer' valign='middle' onClick="getDat e('toDate');">

      </td>

      </tr>

      <tr>
      <td colspan="6" align="center">
      <input type="button" class="button" value="SEARCH" onclick="getByd ate('31')">
      </td>
      </tr>
      <tr>

      <td colspan="5">
      <font color="red">
      <div id="message1" align="center"> </div>
      </font>
      </td>
      </tr>

      </table>
      </fieldset>
      </div>


      <div id="prop_status " style="display: none">

      <fieldset>
      <legend> Proposal By Status </legend>
      <table align="center">
      <td><b> Proposal Status </b></td>
      <td>
      <input type="text" id="status_prop " name="status_pr op" size="25" >
      <img src='./html/img/lov.gif' style='width:20 px;height:15px; cursor:pointer' valign='middle' onclick="getSta tus('31')">
      <input type="hidden" name="status_de sc" value="">

      </td>
      </table>
      </fieldset>
      </div>



      <div id="prop_code" style="display: none">
      <fieldset>
      <legend> Proposal By Code </legend>
      <table align="center">
      <td><b> Proposal Code </b></td>

      <td>
      <input type="text" id="prop_code1 " name="prop_code 1" size="25" >
      <input type="button" class="button" value="SEARCH" onclick="getByC ode('31')">
      <!-- <input type="hidden" name="status_pr op" value="">-->
      </td>
      </table>
      </fieldset>
      </div>

      </td>
      </tr>
      <tr>

      <td colspan="5">
      <font color="red">
      <div id="message" align="center"> </div>
      </font>
      </td>
      </tr>
      <tr>
      <td colspan="4">
      <div id="tables" style="display: none">

      </div>
      <textarea cols="50" rows=25 id="vogus" name="deleteFla g"></textarea>
      </td>
      </tr>
      </form>

      </table>
      </fieldset>

      </body>
      </html>
      [/code]

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        The generated HTML code as plain text which is being generated through AJAX ...goes here ...

        [code=HTML]
        <table>
        <tr>
        <td>


        <table border=1 style='border-color:#557CD7' id=display_tab cellspacing=0 cellpadding=6 align="center">

        <tr>
        <th> Code</th>
        <th> Title</th>
        <th> Sponsor</th>
        <th> Type</th>
        <th> Proposal Creation Date</th>
        <th> Cost(Rs.)</th>
        <th> Status</th>
        <th> Delete Proposal</th>
        </tr>
        <tr>
        <td class='searchbg color'><input type="hidden" value="201" name="proposalC ode" id="proposalCod e_0"/>OCN</td>
        <td class='searchbg color'>Developm ent of client server and GUI based optimization and control network for utilization in the chemical leaching pilot plant of Tata Steel</td>
        <td class='searchbg color'>TISCO, Jamshedpur</td>
        <td class='searchbg color'>Research </td>
        <td class='searchbg color'>2008-08-18</td>
        <td class='searchbg color'>1160000</td>
        <td class='searchbg color'>Approved </td>
        <td class='searchbg color'>
        <!--<input type=hidden name=row_id value = "null"/> -->

        <input type="text" name="deleteFla g" value=''/><input type="checkbox" align="right" value="" name="deletePro posal1" onclick="this.p reviousSibling. value=this.chec ked?'Y':'N'"/>
        </td>
        </tr>




        </table>

        </td>
        </tr>

        <tr align="center">
        <td>
        <table align="center">

        <input type="button" class="button" align="middle" value="Delete" onclick="delete Proposal()" >
        <input type="reset" class="button" align="middle" value="Reset">
        </table>
        </td>
        </tr>

        <tr>
        <td colspan="5">
        <font color="red" size="4">
        <div id="messageDel " align="center"> </div>
        </font>
        </td>
        </tr>

        </table>
        [/code]

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Now i m setting the generated HTML code into the DIV (id=tables).
          Whenever i using document.getEle mentsByName('de leteFlag') then it's working but whenever i suing document.forms['proposal_delet e'].elements['deleteFlag'] then it's not working.
          Please help!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You have a deleteFlag field already in the HTML code.

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by acoder
              You have a deleteFlag field already in the HTML code.
              Is that a cause ...?
              Actually that text area is for test ....it is to extract the HTML code generated through AJAX.
              I think some where DOM parsing is wrong. That's why form can't include the deleteFlag field..What you think.
              By the way if i remove then it will work or not ?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                I don't know. Why don't you test it? Try renaming deleteFlag in the HTML code.

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by acoder
                  I don't know. Why don't you test it? Try renaming deleteFlag in the HTML code.
                  Finally i managed to solve the problem...
                  What i did first .... simple i generated HTML code through AJAX then set it into the innerHTML of the DIV, still it was showing error. Then i stopped putting the HTML through AJAX and put the actual HTML code supposed to be generated in the main HTML code. Then it started responding correct ! ..... ;)
                  What i came to the conclusion, it's problem with div.innerHTML in mozilla then i looked into the site ..there they told that it's a bug .....
                  Then i tested a simple code .. where i set some HTML code into a DIV on body.onload and then tried to access the element added dynamically into DIV, it's working ..... :)
                  Then after a long test i found the error , i simply put the form tag just after body and it started working as it supposed to do .... ;)

                  Can you figure out ?

                  Comment

                  • dmjpro
                    Top Contributor
                    • Jan 2007
                    • 2476

                    #10
                    Originally posted by dmjpro
                    Finally i managed to solve the problem...
                    What i did first .... simple i generated HTML code through AJAX then set it into the innerHTML of the DIV, still it was showing error. Then i stopped putting the HTML through AJAX and put the actual HTML code supposed to be generated in the main HTML code. Then it started responding correct ! ..... ;)
                    What i came to the conclusion, it's problem with div.innerHTML in mozilla then i looked into the site ..there they told that it's a bug .....
                    Then i tested a simple code .. where i set some HTML code into a DIV on body.onload and then tried to access the element added dynamically into DIV, it's working ..... :)
                    Then after a long test i found the error , i simply put the form tag just after body and it started working as it supposed to do .... ;)

                    Can you figure out ?
                    Oh I see ............. Just now after having a deeper look at the main HTML code after this posting ..... the form tag starts just after table tag ....
                    it is something like ....
                    Code:
                    <table><form>..<div></div>...</form></table>
                    I think when loaded into browser it's working but when i add the innerHTML into div dynamically then it stops working .... ;)

                    Comment

                    Working...