butiran

select option

· 1 min read · edit

code

function addOption(sel, text) {
  let opt = document.createElement("option");
  opt.text = text;
  sel.add(opt);
}

let cnt = document.getElementById("cnt");
cnt.style.marginTop = "1em";
cnt.style.background = "#f8f8f8";
cnt.style.border = "1px solid #ddd";

let inSel = document.createElement("select");
inSel.style.width = "320px";
inSel.size = 10;

addOption(inSel, "Problem 01: Magnetic field near long wire");
addOption(inSel, "Problem 02: Lorentz force");
addOption(inSel, "Problem 03: Wave equation");
addOption(inSel, "Problem 04: Solution of wave equation");
addOption(inSel, "Problem 05: Standing and traveling waves");
addOption(inSel, "Problem 06: Electromagnetic wave propagation");
addOption(inSel, "Problem 07: Snell's law");
addOption(inSel, "Problem 08: Lenses and mirrors");
addOption(inSel, "Problem 09: Physics of semiconductor and diode");
addOption(inSel, "Problem 10: Physics of transistor and active components");

cnt.append(inSel);
inSel.options[0].selected = true;
inSel.focus();