Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    createElement("Select") ..... ?

    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);

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    document.createElement('onlytagnamehere')

    Can u detail your needs? What do u indent to do?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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):
    Code:
    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:
    Code:
    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)
    Last edited by brothercake; 03-02-2005 at 04:58 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •