0

I'm making a small website and within that website there is a <select></select> tag. I want to automaticly fill the select when the user presses a key.

Alright? Now let go to the problem, all of the above work fine in Chrome but it doesnt work in IE. Can someone show me a way to make it work in IE?

This is what im working with:

// Action that gets triggered by textfield 2
            function CheckTwo() {
                if (event.keyCode == 13) {
                    AddToList();
                    document.getElementById("two").value = "";
                    GiveFocus("two");
                }                
            }

function AddToList()
            {
                var box = document.getElementById("selectbox");
                var newoption = document.createElement("option");
                newoption.text = document.getElementById("two").value;
                box.add(newoption);
            }

            // Create array of all the items of the <select></select>
            function CalculateList()
            {
                var barcodes = [];
                var options = document.getElementsByTagName("option");
                for (var i = 0; i < options.lenght; i++)
                {
                    barcodes.push(options[i].text);
                }
                var barcodestring = barcodes.join(",");
            }

I dont think the html is relevant for this kind of question becuase i believe that internet explorer cant handle the javascript. But here it is in case it is the problem:

 <tr>


<td>Bonregel:</td>
                    <td><input type="text" name="bonregel" id="two" onkeyup="CheckTwo()" /></td>
                </tr>
                <tr>
                    <td>Bonlijst:</td>
                    <td><select id="selectbox" multiple></select></td>
                </tr>
                <tr>
9
  • Which version of IE? Commented Jun 12, 2015 at 12:47
  • The version i have is IE 10 Commented Jun 12, 2015 at 12:50
  • whether that function is triggering?? try adding an alert inside if Commented Jun 12, 2015 at 12:52
  • Wich if? The one in the Check() function? Commented Jun 12, 2015 at 12:53
  • 1
    Works fine here in IE10 & IE 11: jsfiddle.net/re6djgfL/1 Yet try onkeypress instead and pass the event to it CheckTwo(event) and check event.which Commented Jun 12, 2015 at 13:03

1 Answer 1

1

Try to change your function and your call a bit.

function CheckTwo(event){
    var tKey = (event.which) ? event.which : event.keyCode;
    if (tKey == 13){
        AddToList();
        document.getElementById("two").value = "";
        GiveFocus("two");
    }                
}

<input type = 'text' name = 'bonregel' id = 'two' onkeyup = 'CheckTwo(event)' />

https://jsfiddle.net/Log490jk/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.