469,312 Members | 2,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

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 24376
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

Post your reply

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

Similar topics

4 posts views Thread by masantha wee | last post: by
10 posts views Thread by Noozer | last post: by
10 posts views Thread by Eric-Sebastien Lachance | last post: by
6 posts views Thread by Nx | last post: by
5 posts views Thread by Magician | last post: by
5 posts views Thread by John Grandy | last post: by
4 posts views Thread by Geoff Cox | last post: by
4 posts views Thread by Big Moxy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.