/    Sign up×
Community /Pin to ProfileBookmark

Inline js not working in IE8

I am trying to use some inline javascript set the value of another menu when a value is selected in a menu.

Example:

<select name=”menu1″ id=”menu1″>
<option value=”Hello” onclick=”javascript:document.getElementById(‘menu2’).selectedIndex = 2″>Hello</option>
<option value=”World”>World</option>
</select>

Anyways this script should select the second option in the menu2. This works fine in Opera and Firefox but not in IE. I am not very adapt with javascript, but I am not sure why this is not working.

Wondering if anyone may have and idea how to make sure this works in IE.

Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 21.2009 — IE does not support events upon an [B]option[/B] element ([B]onclick[/B] your case). Use [B]onchange[/B] applied upon the[B] select[/B] element
<i>
</i>&lt;select name="menu1" id="menu1" onchange="document.getElementById('menu2').selectedIndex = Number(this.value);"&gt;
&lt;option value="2"&gt;select the 3rd option on menu2&lt;/option&gt;
&lt;option value="3"&gt;select the 4th option on menu2&lt;/option&gt;
&lt;/select&gt;
Copy linkTweet thisAlerts:
@brossowAug 26.2009 — I'm having a similar issue as the OP and hope it's okay to piggyback on this thread.

In my case, I have a dropdown menu. When an item is selected from the menu, I want a new menu to appear. I'm using javascript and a series of hidden DIVs to accomplish this, and it works beautifully in Firefox. However, for reasons now obvious to me, it doesn't work in Internet Explorer.

Would someone be willing to look at a sample page and let me know if there's a way to fix this so it works across all major browsers? Here's the link: http://rossow.us/tmp/sample.html. On this sample page, the links across the top work in IE (as expected) and are only there to demonstrate what I [I]want[/I] to occur when an option from the select list is chosen.

The code for the select is as follows:

[CODE] <select name="scope">
<optgroup label="Select one...">
<option value="Initiative" onclick="showonlyone('scope1');">Initiative</option>
<option value="Geography" onclick="showonlyone('scope2');">Geography</option>
<option value="Retailer" onclick="showonlyone('scope3');">Retailer</option>
<option value="Grower" onclick="showonlyone('scope4');">Grower</option>
<option value="Salesperson" onclick="showonlyone('scope5');">Salesperson</option>
</optgroup>
</select>
[/CODE]


I'm familiar with javascript only to the extent that I'm able to copy and paste someone else's code and do a basic amount of troubleshooting, and that extends into HTML with options such as 'onclick' that I simply don't have enough experience with to understand. I've tried to sort this out on my own, but it's not working and so I appreciate any guidance.

Thanks a TON,

Brent
Copy linkTweet thisAlerts:
@KorAug 27.2009 — I'm having a similar issue as the OP and hope it's okay to piggyback on this thread.[/QUOTE]
I would have appreciated you if have been reading my previous post. Once again:

IE does not support events upon an option element ([B]onclick[/B] your case). Use [B]onchange[/B] applied upon the select element.
Copy linkTweet thisAlerts:
@brossowAug 27.2009 — I would have appreciated you if have been reading my previous post. Once again:

IE does not support events upon an option element ([B]onclick[/B] your case). Use [B]onchange[/B] applied upon the select element.[/QUOTE]


With all due respect, I [B]did[/B] read your previous post. [...]

[B]EDIT:[/B] Never mind -- although I didn't understand 'onchange' at the time I posted this yesterday, I've now got it working. Thanks anyway!
×

Success!

Help @webmaster54880 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...