Re: Creating a table in javascript
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 30 May 2006 15:17:06 GMT
fjleon@xxxxxxxxx wrote:
var masculino = document.createElement("option");I don't know what you tried, but IE supports the 'text' attribute just
masculino.setAttribute("value","M");
masculino.text="Masculino";
masculino.innerText="Masculino";
var femenino = document.createElement("option");
femenino.setAttribute("value","F");
femenino.text="Femenino";
femenino.innerText="Femenino";
Mozilla doesn't support innerText, and IE doesn't support text, so i am
using both.
Is there a better way?
fine. This should work equally well on either browser:
var selectsexo = document.createElement("select");
var masculino = document.createElement("option");
masculino.value = "M";
masculino.text="Masculino";
var femenino = document.createElement("option");
femenino.value = "F";
femenino.text="Femenino";
selectsexo.options.add(masculino);
selectsexo.options.add(fememino);
Or reduce the repetition by using a loop:
var selectsexo = document.createElement("select");
var options = [["M", "Masculino"], ["F", "Femenino"]];
for (var i=0; i < options.length; i++) {
var opt = document.createElement("option");
opt.value = options[i][0];
opt.text = options[i][1];
selectsexo.options.add(opt);
}
.
- Follow-Ups:
- Re: Creating a table in javascript
- From: fjleon
- Re: Creating a table in javascript
- 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: IE Problem : Dynamic Javascript in PHP constructor
- Next by Date: Re: keeping focus on a text field
- Previous by thread: Re: Creating a table in javascript
- Next by thread: Re: Creating a table in javascript
- Index(es):