473,386 Members | 1,867 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.

onclick not working in IE but working in firefox !!

Hi

I am facing a problem with my code ....
this is what I am doing ...
I am having a link on the page which says "add tab" o clicking this link I add a new tab to the page, I write the code for that in Javascript function, I set the attributes of that tab in there. One of the attribute is on click. I am able to achieve what I want in mozilla but IE is not doing anything onclicking the tab.

I am attaching the code snippet as well ... see if you can help ... I am stuck ...

Expand|Select|Wrap|Line Numbers
  1. function addTab(obj)
  2.         {
  3.             tabCount=tabCount+1;
  4.             var newSpan = document.createElement("span");
  5.             newSpan.setAttribute("id","tab"+tabCount);
  6.  
  7.             var newInput = document.createElement("input");
  8.             newInput.setAttribute("type","button");
  9.             newInput.setAttribute("value","New Tab "+tabCount);
  10.             newInput.setAttribute("onclick","changeTab(this)");
  11.             newInput.setAttribute("id",tabCount);
  12.  
Regards,
Tarun Chandel
Jun 26 '06 #1
8 24974
Hi

I am facing a problem with my code ....
this is what I am doing ...
I am having a link on the page which says "add tab" o clicking this link I add a new tab to the page, I write the code for that in Javascript function, I set the attributes of that tab in there. One of the attribute is on click. I am able to achieve what I want in mozilla but IE is not doing anything onclicking the tab.

I am attaching the code snippet as well ... see if you can help ... I am stuck ...

Expand|Select|Wrap|Line Numbers
  1. function addTab(obj)
  2.         {
  3.             tabCount=tabCount+1;
  4.             var newSpan = document.createElement("span");
  5.             newSpan.setAttribute("id","tab"+tabCount);
  6.  
  7.             var newInput = document.createElement("input");
  8.             newInput.setAttribute("type","button");
  9.             newInput.setAttribute("value","New Tab "+tabCount);
  10.             newInput.setAttribute("onclick","changeTab(this)");
  11.             newInput.setAttribute("id",tabCount);
  12.  
Regards,
Tarun Chandel
I had the same problem. Anyone find a solution?

T
Dec 8 '06 #2
Instead of hard-coding the event handler, include this code in a JS file (mine's called dhtml-core.js:

Expand|Select|Wrap|Line Numbers
  1. var addEvent;
  2. if (document.addEventListener) {
  3.     addEvent = function(element, type, handler) {
  4.         element.addEventListener(type, handler, null);
  5.     }
  6. }
  7. else if (document.attachEvent) {
  8.     addEvent = function(element, type, handler) {
  9.     element.attachEvent("on" + type, handler);
  10.     }
  11. }
  12. else {
  13.     addEvent = new Function; // not supported
  14. }
Then, use the call:
Expand|Select|Wrap|Line Numbers
  1. addEvent(someObject, "click", functionName, false) ;
It'll work across various browsers.
Dec 8 '06 #3
Kasya
57
If You Use INternet Explorer 7 Beta for WINDOWS VISTA You Can Use It
Dec 9 '06 #4
benhunt,

Does that work with parameters? I am having major problems with IE not allowing you to change the onChange attribute of an element.

Jake
Dec 12 '06 #5
AricC
1,892 Expert 1GB
Post the HTML along with the JS if your still having this problem.
Dec 12 '06 #6
No, doesn't use parameters in itself. I've never found that's stopped me though. Normally, the element's position in the DOM gives me what I need. Or, you can call different functions from different flavours of elements.
Dec 22 '06 #7
This is pure fluke. I've stumbled across the solution. What you do is hard-code the function(){ ... your code here ...} instead of the myfunction() call... Forgot you could do this in JS. I'm seeing this technique used all over the place.

Expand|Select|Wrap|Line Numbers
  1. var listener = addEventListener(elem, "click", function() {
  2.     alert("You clicked me!");
  3. });
Dec 22 '06 #8
Hi,

I have a problem with Internet explorer as in my web applications second page, within few minutes I am getting this error-
The web page cannot be displayed. application is running fine in localhost but page expires if running on some other servers. In Mozilla Firefox its working fine. Please Help.
Oct 15 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: masantha wee | last post by:
Hi all, I am using Firefox and embedding Javascript in html. I understand that we can use mouse events by coding them in the body of html (by creating a button or anything and by adding in the...
10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
10
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work...
6
by: Nx | last post by:
i've got it all working nicely in firefox, but whenever i test it in IE none of the onclick events are triggered. i'm using an xsl to transform an rss feed into a photogallery. when i try to...
5
by: Magician | last post by:
Hello. I am trying to set the onclick event for images through a function, but the event is triggered as soon the page loads, then will not work when the image is clicked. Can anyone suggest what...
9
by: whitgurley | last post by:
I've searched the web as well as I can for a solution to this problem but have found nothing and just don't know enough about JavaScript to figure out what's going. What I'm trying to do is convert...
10
by: NeoTubNinja | last post by:
I have a select statement with various numbers. Upon clicking on one of the options, you are sent to a page that puts the option value in a session and returns back to the previous page. When it...
5
by: John Grandy | last post by:
I wrote a function to populate my dropdowns on the client-side. The function adds <optionelements to the <selectonly if none are initially present. I call the population function from either...
4
by: Geoff Cox | last post by:
Hello the following onclick works with IE 7 but not with Firefox 2.0.0.9. any ideas please? <form action=""> <select name="txtId"> <option="word1">word1</optionetc </select>
4
by: Big Moxy | last post by:
test page - http://projects.missioninternet.com/proweb/clients/test.php. When I added the onclick event so that I could employ ajax on this page the stylesheet formatting for this <lidisappeared....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.