Re: Creating a table in javascript
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Wed, 31 May 2006 19:11:15 +1000
fjleon@xxxxxxxxx wrote:
Ok, apparently IE needs that rows go inside a tbody, otherwise it
doesn't work.
So i added the tbody and it works.
You may find it easier to use inesertRow rather than add a tbody. It requires a lot less code, e.g.:
var newTable = document.createElement('table');
var newRow = newTable.insertRow(-1);
var newCell = newRow.insertCell(-1);
The table now has a single row and cell and is ready to be added to the document - no need to explicitly create a tbody, nor to create then add elements.
<URL:http://developer.mozilla.org/en/docs/DOM:table#Methods>
Now, i need to add a <select> with 2 options inside it.
I tried doing it this way:
var td3 = document.createElement("TD");
var selectsexo = document.createElement("select");
var masculino=new Option("MASCULINO","M");
var femenino=new Option("FEMENINO","F");
selectsexo.appendChild(masculino);
selectsexo.appendChild(femenino);
td3.appendChild(selectsexo);
But again, doesn't work on IE.
What will work in IE is (wrapped for posting):
var selectsexo = document.createElement("select");
selectsexo.options[selectsexo.options.length] =
new Option("MASCULINO","M");
selectsexo.options[selectsexo.options.length] =
new Option("FEMENINO","F");
td3.appendChild(selectsexo);
There is a relevant thread here:
<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/226caadb3bd3ca60/61dc315bf5d3baea?q=new+option+text+value+robg&rnum=1#61dc315bf5d3baea>
--
Rob
.
- References:
- Creating a table in javascript
- From: fjleon
- Re: Creating a table in javascript
- From: fjleon
- Creating a table in javascript
- Prev by Date: Re: tutorial on dynamic SID generation
- Next by Date: Re: To allow left click only on some elements of web page NOT all elements
- Previous by thread: Re: Creating a table in javascript
- Next by thread: Automated Form submission
- Index(es):
Relevant Pages
|