javascript - adding items to <select> in IE5 -
ill awnser first question... why ie5 wonder, because on windows ce device im working im limited use ie5. application i've made uses webpage couple of elements.
i have 2 textfields , 1 list or <select> want transfer value of 1 textbox list. i've got working in ie 10 , chrome when tested webpage on device did not send value of textfield 2 list. can me solve issue?
this html code:
<tr> <td>locatie:</td> <td><input type="text" id="one" onkeyup="checkone()" name="locatie" value="{locatie}" /></td> </tr> <tr> <td>bonregel:</td> <td><input type="text" name="bonregel" id="two" onkeyup="checktwo(event)" /></td> </tr> <tr> <td>bonlijst:</td> <td><select id="selectbox" multiple></select></td> </tr> <tr> <td></td> <td><input type="submit" value="verzenden" id="sub" onclick="checkcontent()" /></td> </tr> <tr> <td></td> <td><input type="button" value="velden legen" id="reset" onclick="clearfields()" /></td> </tr> and have javascript functions adding data list:
function addtolist(field) { // create option object var opt = document.createelement("option"); document.getelementbyid("selectbox").options.add(opt); opt.text = document.getelementbyid("two").value; opt.value = document.getelementbyid("two").value; } function checktwo(event) { var field = document.getelementbyid("two").value; var tkey = (event.which) ? event.which : event.keycode; if (tkey == 51) { addtolist(field); givefocus("two"); } } // gives focus specified component function givefocus(id) { document.getelementbyid(id).focus(); } // action gets triggered textfield 1 function checkone() { if (event.keycode == 13) givefocus("two"); } edit
i've figured out button takes priority kind of reason. button submits press enter. when press enter in second textfield should send data list. there solution button doesnt take priority
heres fiddle of full code: https://jsfiddle.net/3jywt8v1/1/
on ie5, need use option constructor rather createelement:
function addtolist(field) { // create option object var val = document.getelementbyid("two").value; var opt = new option(val, val); document.getelementbyid("selectbox").options.add(opt); } it works on modern browsers.
i think add, you're using, compatible way add option list, if isn't it, may need add via assignment instead:
var options = document.getelementbyid("selectbox").options; options[options.length] = opt; ...but again, think add better supported in 90s.
Comments
Post a Comment