List Info

Thread: Help:Dynamic create a form with a table for layout




Help:Dynamic create a form with a table for layout
country flaguser name
United States
2007-08-28 01:33:59
Hi,all.
I want to create a form with a table for layout,but it
doesn't
works,the browser displays nothing. but if i donot use the
table,it
works well,the browser can display a input textfield.
below is the main code.
------------------------------------------------------------
-------------------------------------------------------
<BODY>
 <div id="formTest">

  </div>
 <script>
 /*
   The form to create
    <form>
      <table>
        <tr>
          <td><input type="text"
name="test"></td>
       </tr>
   </table>
   </form>
 */
  aDiv=document.getElementById("formTest");

   aTable=document.createElement("table");

   tr1=document.createElement("tr");
   aTable.appendChild(tr1);
   td1=document.createElement("td");
   tr1.appendChild(td1);
   aInput=document.createElement("input")
   aInput.setAttribute("type","text");
   aInput.setAttribute("name","test");
   td1.appendChild(aInput);
   aForm=document.createElement("form");

   aForm.appendChild(aInput);

   aDiv.appendChild(aForm);
 </script>
</BODY>
------------------------------------------------------------
------------------------------------------------------------
---------
Anyone knows why?thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Help:Dynamic create a form with a table for layout
country flaguser name
United States
2007-08-29 14:31:22
You need to attach the rows to a tbody, and a tbody to the
table. The
browsers "fix" it for you by adding tbodies, but
it doesn't like it
dynamically.

The order is:

table
->tbody
--->tr
------>td

So:
var tbl = document.createElement("table");
var tbody = document.createElement("tbody");
var tr = .......
var td = ........

td.appendChild(document.createTextNode("Hello
World!"));

tr.appendChild(td);
tbody.appendChild(tr);
tbl.appendChild(tbody);

And then do whatever you want with the table.

~A!

On Aug 28, 2:33 am, Andvar <Andvar2...gmail.com> wrote:
> Hi,all.
> I want to create a form with a table for layout,but it
doesn't
> works,the browser displays nothing. but if i donot use
the table,it
> works well,the browser can display a input textfield.
> below is the main code.
>
------------------------------------------------------------
-------------------------------------------------------
> <BODY>
>  <div id="formTest">
>
>   </div>
>  <script>
>  /*
>    The form to create
>     <form>
>       <table>
>         <tr>
>           <td><input type="text"
name="test"></td>
>        </tr>
>    </table>
>    </form>
>  */
>   aDiv=document.getElementById("formTest");
>
>    aTable=document.createElement("table");
>
>    tr1=document.createElement("tr");
>    aTable.appendChild(tr1);
>    td1=document.createElement("td");
>    tr1.appendChild(td1);
>    aInput=document.createElement("input")
>   
aInput.setAttribute("type","text");
>   
aInput.setAttribute("name","test");
>    td1.appendChild(aInput);
>    aForm=document.createElement("form");
>
>    aForm.appendChild(aInput);
>
>    aDiv.appendChild(aForm);
>  </script>
> </BODY>
>
------------------------------------------------------------
------------------------------------------------------------
---------
> Anyone knows why?thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )