...

View Full Version : createElement("Select") ..... ?



owen_yuen
03-02-2005, 08:23 AM
Why I only create a EMPTY selection drop down box using the following code.... ? Any advice I am appreicate

var lastRow = tbl.rows.length;
var row = tbl.insertRow(lastRow);
var cell = row.insertCell(1);
var am = "<select id=selBidReceivedIsPM name=selBidReceivedIsPM>"
am = am + "<option value=0>AM</option>"
am = am + "<option value=1>PM</option>"
am = document.createElement(am);
cell.appendChild(am);

Kor
03-02-2005, 04:45 PM
document.createElement('onlytagnamehere')

Can u detail your needs? What do u indent to do?

brothercake
03-02-2005, 05:55 PM
You're trying to create an element using serialised text - effectively treating createElement as though it were innerHTML

innerHTML is a serialised representation of HTML as text - it's not nodes, it's just text - so you can write pretty much anything that way (providing your page is served as text/html):


cell.innerHTML += '<select id="selBidReceivedIsPM" name="selBidReceivedIsPM">'
+ '<option value="0">AM</option>'
+ '<option value="1">PM</option>';


However createElement creates individual element nodes - each <select> and <option> is a element node; the text inside each option is a text node.

So, to create the selector that way, you'd want something like this:


var selector = document.createElement('select');
selector.id = 'selBidReceivedIsPM';
selector.name = 'selBidReceivedIsPM';
cell.appendChild(selector);

var option = document.createElement('option');
option.value = '0';
option.appendChild(document.createTextNode('AM'));
selector.appendChild(option);

option = document.createElement('option');
option.value = '1';
option.appendChild(document.createTextNode('PM'));
selector.appendChild(option);

You could simply that though, by keeping the option data in an array and building them iteratively (with a for() loop)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum