View Full Version : createElement("Select") ..... ?
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);
Can u detail your needs? What do u indent to do?
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';
var option = document.createElement('option');
option.value = '0';
option = document.createElement('option');
option.value = '1';
You could simply that though, by keeping the option data in an array and building them iteratively (with a for() loop)
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.