Pete
Pete

Reputation: 51

Show up value of select option in IE

I have a problem with a html select object and its options in IE.

My html

<select  id="Select1" onchange="closeMenu1(this.value)">
                                                 <option></option>
                                                 <option>1</option>
                                                 <option>2</option>

And the javascript

            function closeMenu1 (x) {
                                           var show = document.getElementById("divID");
                                           show.innerHTML = x;
                           }

Now, in every browser except the IEs the divID will show up the value which I selected in the select object. But IE doesn’t. Can somebody please tell me a way around that?

Thanks.

Upvotes: 2

Views: 337

Answers (3)

trex005
trex005

Reputation: 5115

your options actually do not have values set, so you have two options
1) Set them

<select  id="Select1" onchange="closeMenu1(this.value)">
<option value=''></option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>

2)Use The selected index's text

Upvotes: 1

Abdullah Jibaly
Abdullah Jibaly

Reputation: 54790

Try getting the value from inside your closeMenu1 function instead of trying to pass it in:

function closeMenu1() {
    var val = document.getElementById("Select1").value;
    var show = document.getElementById("divID");
    show.innerHTML = val;
}

Then change the onchange attribute to simply onchange="closeMenu1()".

Upvotes: 0

Chandu
Chandu

Reputation: 82903

Change your onchange event handler to as given below:

<select  id="Select1" onchange="closeMenu1(this.options[this.selectedIndex].value)">
  <option></option>
  <option>1</option>
  <option>2</option>
</select>

Upvotes: 0

Related Questions