create select element's value can't see

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • koyanpaing
    New Member
    • Mar 2010
    • 26

    create select element's value can't see

    Hello everyone,
    I have a problem with these,
    I can set value to input text box but i can't set value to dropdown button.
    I think my code is wrong in somewhere.
    can you help me please?

    Code:
                   var cell8 = row.insertCell(7);
    		var element8 = document.createElement("input");
    		element8.setAttribute("size",5);
    		element8.setAttribute("value","somedata");
    		element8.type = "text";
    		cell8.appendChild(element8);
    		
    		var cell9 = row.insertCell(8);
    		var element9 = document.createElement("select");
    		element9.setAttribute("name","test");
    		var element9text = document.put("option","aaa");
    		element9.appendChild(element9text);
    		cell9.appendChild(element9);
    Thanks and Regards
    Yan Paing
    Last edited by Dormilich; Mar 26 '10, 09:24 AM. Reason: Please use [code] tags when posting code
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Yes the way u have added is wrong. It should be in different way.

    for the element9 (select) you have to dynamically create options and append to element9.

    demo code:

    Code:
    var opt1 = document.createElement('option');
    opt1.value="demo";
    opt1.text="demo";
    
    element9.appendChild(opt1);
    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      you may also use new Option() to create an option element.

      Comment

      Working...