onclick doesn't work in IE

behets
behets used Ask the Experts™
on
IE 8 and 7 doesn't call the function specified in the onclick.

The function is dynamicly added using Jquery & xml
You can find the code below,

The code works perfect on firefox, chrome ect,

You can also found the final html after the javascript functions are called in the code section.

'showhint' Works perfect, showhint don't,
i also placed a break point in the function to check when it's being called, when i call it in a href, it works perfect, but when i click on the td ( & in IE), nothing happens...

Any suggestions ?
Ty,

javascript code :
 
			$.ajax({
            type: "GET",
            url: "xml/?page=" + xmlgetpage + "&maand=" + month  + "&jaar=" + year,
            dataType: "xml",
            success: function(xml) {
                $(xml).find('event').each(function(){
                    var xmlday = parseInt($(this).find('day').text());
					var xmlmonth = parseInt($(this).find('month').text());
					var mxlyear = parseInt($(this).find('year').text());
					var xmlcomment = $(this).find('comment').text()
					if(year == mxlyear && xmlmonth == month){
					$('.day' + xmlday).attr('title',xmlcomment).addClass("event-day");
					$('.day' + xmlday).attr("onclick","javascript:poptastic('?page=" + xmlgetpage + "&dag=" + xmlday + "&maand=" + ( xmlmonth + 1) + "&jaar=" + mxlyear +"')");
					}
 
                 });
                $(".event-day").attr("onMouseover","javascript:showhint($(this).attr(\"title\"),this, window.event, '200px')");
			}
            });
 
-----------------------------
 
final html code:
 
...
<TD class="current-month day15">15</TD>
<TD class="current-month day16 event-day" onmouseover="javascript:showhint($(this).attr(&quot;title&quot;),this, window.event, '200px')" title="Er is  1 afspraak gepland" onclick="javascript:v('?page=afspraken&amp;dag=16&amp;maand=7&amp;jaar=2009')">16</TD>
<TD class="current-month current-day day17">17</TD>
<TD class="current-month day18">18</TD>
...

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Try remove the "javascript:", you don't need it.

onclick="v('?page=afspraken&amp;dag=16&amp;maand=7&amp;jaar=2009')"

Open in new window

Author

Commented:
Already tried that one,

Actualy,   originaly it wasn't there.
Your html sample uses function named "v", the JS code creates function call "poptastic"??
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
indeed,

I copy paste the generated code from the IE develop tool using copy inner thml of the tr tag,
In the copied code the function is called V, but when i inspect the onclick in the IE develop tool it's exactly ( as it should be) 'poptastic('?page=afspraken&dag=16&maand=7&jaar=2009')'

When i changed somthing in it, like adding a ; it some how updates it's dom corectly and everything works.

However, i'ts a bug of IE i think, but does anyone know how to work around it ?
Does V equate to anything?  Does a script create aliases at all?  If you type 'v' in the console, is it undefined?  What happens if you change the name?

Author

Commented:
V is undefined, the IE tool changed the function name to V when exporting the inner html...

However, i can see the function in the dom, and if i change it there (like adding a ';') it works o_0

Now if i change this in the file itself, it doesn'"t do anything.

And to make it complete, when i removed the ';' agian using the develop tool in the dom, it works again...

 
Some wierdness there...!  Sorry I have no more ideas... Good luck.
Top Expert 2004

Commented:
Please link to a demo page so we can get a better grasp of the page structure. There is no way that v() is undefined if it causes changes, so it must occur somewhere.

Author

Commented:
Sure,

You can login at this page: http://immotool.be/new/login.php 

email 'demo' and pass 'demo'

the onclick problem is when you try to click on day 16 on the calender you see right in front after login in.

I also found out that it works perfect in a early version of chrome, but not in the last one.
And it works again in Opera but not safari.

In IE Developer tools, I added a ; to the end of the javascript in the onclick handler and it then worked fine..

Author

Commented:
Exactly, read this one:

------------------

                                                                                Was this comment helpful?                          Yes                  No                    behets:             V is undefined, the IE tool changed the function name to V when exporting the inner html...

However, i can see the function in the dom, and if i change it there (like adding a ';') it works o_0

Now if i change this in the file itself, it doesn'"t do anything.

And to make it complete, when i removed the ';' agian using the develop tool in the dom, it works again...

------------------
When you change it in the code, and reload it it doesn't work, i you remove it in the tool an conferm it, it works again... Ooh I love IE

I think IE has some bug's with updating his DOM corectly, but still, it should be possible to fix this little bug or work around/avoid it...
Ah sorry - yes didn't read that post properly :)

But I develop for 10 browsers including 3 versions of IE all the time, creating event handlers etc and have never experienced anything like this... Most strange

Have you considered another method of assigning the onclick handler?  I never in practice directly assign code to the onclick attribute, but rather use a frameworks subscribe() method.  With YUI (for example) I would use:

YAHOO.util.Event.addListener('element_id', 'click', function(e){
    // Onclick handler code here
});

Open in new window

Author

Commented:
Thank you for the last post, it gave me a id for the final solution,

indeed it would be possible, I searched in Jquery and just fixed it with anonomous functions and the .click event of Jquery. Some how the framework use other methodes better than onlick the way above,

However it works.
Thanks for al the replay's
Top Expert 2004

Commented:
Most likely your JavaScript was being dynamically changed somehow in IE. Glad you got it working with jQuery -- they tend to store all click information in their own data structure, so none of it gets lost if you stack them.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial