473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

onchange not working in internet explorer

I have a page and if the user has javascript enables I am trying to
dynamically change a link to a sitemap to a dropdown menu (that when
the option is changed will forward the user to another page). Here's
the code

try{

var sel = document.createElement("select");

sel.setAttribute("onchange", "alert('');");

for(var i=0;i<this.labels.length;i++){

var op = document.createElement("option");

op.value = this.hrefs[i];

op.appendChild(document.createTextNode(this.labels[i]));

sel.appendChild(op);

}

var ql = document.getElementById("quicklinks");

ql.replaceChild(sel, ql.firstChild);

if(document.body){

alert(document.body.innerHTML);

alert(sel.getAttribute("onchange"));

}

}catch(e){alert(e.name+"\n"+e.message)

}

This works fine in firefox and when I display the generated html it
shows the select node w/ the appropriate onchange attribute in both ff
and ie. The problem is that the event is not working in ie. For some
reason changing the option does nothing. Any ideas? Also is this the
most unobtrusive way to achieve a quick links menu. Part of me is
considering just using an html/css vertical menu instead of a pull
down.

Thanks Guys

Mar 16 '07 #1
3 32885
On Mar 16, 10:05 am, "Mister Joe" <mrjoefri...@gmail.comwrote:
I have a page and if the user has javascript enables I am trying to
dynamically change a link to a sitemap to a dropdown menu (that when
the option is changed will forward the user to another page). Here's
the code

try{

var sel = document.createElement("select");

sel.setAttribute("onchange", "alert('');");

for(var i=0;i<this.labels.length;i++){

var op = document.createElement("option");

op.value = this.hrefs[i];

op.appendChild(document.createTextNode(this.labels[i]));

sel.appendChild(op);

}

var ql = document.getElementById("quicklinks");

ql.replaceChild(sel, ql.firstChild);

if(document.body){

alert(document.body.innerHTML);

alert(sel.getAttribute("onchange"));

}

}catch(e){alert(e.name+"\n"+e.message)

}

This works fine in firefox and when I display the generated html it
shows the select node w/ the appropriate onchange attribute in both ff
and ie. The problem is that the event is not working in ie. For some
reason changing the option does nothing. Any ideas? Also is this the
most unobtrusive way to achieve a quick links menu. Part of me is
considering just using an html/css vertical menu instead of a pull
down.

Thanks Guys


I actually got the event to work by using attachEvent and
addEventListener...but I'm still wondering if what I'm doing is the
most unobtrusive way.

Mar 16 '07 #2

Mister Joe wrote:
I actually got the event to work by using attachEvent and
addEventListener...but I'm still wondering if what I'm doing is the
most unobtrusive way.
use -
element.onchange=FuncName
or
element.onchange=function(){ doWhatever() }

the above works in all browsers, afaik.

Mar 16 '07 #3
On Mar 16, 3:05 pm, "Mister Joe" <mrjoefri...@gmail.comwrote:
I have a page and if the user has javascript enables I am trying to
dynamically change a link to a sitemap to a dropdown menu (that when
the option is changed will forward the user to another page). Here's
the code

try{

var sel = document.createElement("select");

sel.setAttribute("onchange", "alert('');");

for(var i=0;i<this.labels.length;i++){

var op = document.createElement("option");

op.value = this.hrefs[i];

op.appendChild(document.createTextNode(this.labels[i]));

sel.appendChild(op);

}

var ql = document.getElementById("quicklinks");

ql.replaceChild(sel, ql.firstChild);

if(document.body){

alert(document.body.innerHTML);

alert(sel.getAttribute("onchange"));

}

}catch(e){alert(e.name+"\n"+e.message)

}

This works fine in firefox and when I display the generated html it
shows the select node w/ the appropriate onchange attribute in both ff
and ie. The problem is that the event is not working in ie. For some
reason changing the option does nothing. Any ideas? Also is this the
most unobtrusive way to achieve a quick links menu. Part of me is
considering just using an html/css vertical menu instead of a pull
down.

Thanks Guys
As far as I know, the problem is that Internet Explorer recognizes
something changed just after you lose focus on that element. That is,
it "thinks" you're still changing it and will wait until you click
somewhere on the side or on another element. If so, try combining with
<option onclickor something like that.

Mar 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Yve | last post by:
Hallo, this testweb works well in Mozilla and Netscape but not in Internet Explorer. http://www.netzwerkservice.com/test/frame/test_javascript_1007/ As I am not good at JavaScript I have...
6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
1
by: kebabkongen | last post by:
Hi, I'm working on a JavaScript that is enabling / disabling a select element according to whether a checkbox is selected or not. This works fine in Firefox, but in Internet Explorer (v 6.0.2900)...
2
by: antiinertia | last post by:
How does one find the value of a drop down in Internet Explorer? The form below works in Firefox and Safari. But not in Internet Explorer. Can someone tell me how to code this so IE understands...
1
by: suneel271 | last post by:
code working in internet explorer but not in mozilla and iam getting erroe like window.event has no properties and here is the code <%@ page language="java" contentType="text/html;...
4
by: eschneider | last post by:
I get the following error when trying to browse the .asmx. I get the same thing when trying to add a reference. using .NET 2.0 There is no error message. Any ideas? Thanks,
5
by: mukeshrasm | last post by:
Hi I am using AJAX to display the value in selection/list box. this code is working fine in Firefox Mozila browser but it is not working in Internet Explorer so please tell me how this will work...
1
by: loudey | last post by:
hi I'm making a macro in excel that loads up internet explorer and fills out a form. I'm able to do all of that but i have a hard time to trigger a javascript onchange event that is triggered when a...
0
by: Akpo | last post by:
Hi all, i am writing an ajax and php application for a sec ondary school, and i want the contents of one select list to be based on the values of the select list that appears before it. The issue is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.