How to create form element dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ITProgrammer985
    New Member
    • May 2010
    • 13

    How to create form element dynamically

    Hi,

    I have the following Script, which dynamically creates divs

    [code=javaScript]
    <div id="scr1" style="width: 784px; cursor:pointer; ">
    <script language='javas cript' type='text/javascript'>
    <%
    i = 0
    While i < Counter
    MyBase.Response .Write("var NewDiv = document.create Element('div'); ")
    MyBase.Response .Write("NewDiv. Id ='Div" + i.ToString + "';")
    MyBase.Response .Write("NewDiv. className ='default';")
    MyBase.Response .Write("scr1.ap pendChild(NewDi v);")
    MyBase.Response .Write("NewDiv. innerHTML = '" + DataTableObject .Rows(i)(2).ToS tring() + "';")
    i = i + 1
    End While
    %>
    </script>
    </div>
    [/code]
    i am fetching the Counter value and the innerHTML from the database using VB.net and using try catch handler
    It works fine in IE,Opera and Chrom however, it doesn't seem to work with Firefox. Nothing happens in Firefox when load the page.

    Please Help

    Thanks in advance for any help.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    i suspect that you would need to retrieve the node where you want to append correctly with - the following line:
    Code:
    MyBase.Response.Write("scr1.appendChild(NewDiv);")
    should look like:
    Code:
    MyBase.Response.Write("document.getElementById('scr1').appendChild(NewDiv);")
    ?

    kind regards

    Comment

    • ITProgrammer985
      New Member
      • May 2010
      • 13

      #3
      Originally posted by gits
      i suspect that you would need to retrieve the node where you want to append correctly with - the following line:
      Code:
      MyBase.Response.Write("scr1.appendChild(NewDiv);")
      should look like:
      Code:
      MyBase.Response.Write("document.getElementById('scr1').appendChild(NewDiv);")
      ?

      kind regards
      thank u so much for your help gits
      it worked

      Comment

      Working...