ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Rep:
Javascript onclick doesn't work in IE
Hi,
I have been searching on google to find the answer for my question, but I have not succeeded to find the answer for my question, that's why I m trying to find my answer in here.
I have a dynamic page with 10 anchors and 10 div element in it. Each anchor is named like anchor_1, anchor_2, ... and each div is called div_1, div_2, ... .
I have created an oclick event handler for each anchor to change the content of the corresponding div element. For example, if you press on a_23, div_23 contents should be changed.
PHP Code:
<a id="anchor_23" onclick="vote_link(this)"></a>
And I have a javascript function called vote_link(this) which grabs this.id and find the corresponding div element and change it. Everything works in FF, but in IE it even doesn't call my function
I have bunch of onclick event handlers and since they worked on FF I thought everything is alright. Fortunately or Unfortunately I don't have IE on my computer to test everything immediately, so almost non of my javascript simple functions work in IE.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Original Poster
Rep:
Thanks, but that didn't help me. I'm trying to use YUI library. They have several useful functions that can help me to some level. Because all data are inside a tab, not everything works fine, when the tab content are changed as I wanted. That's why I tried to use inline event handlers. In YUI they have a function that can return an array of element based on their class or tag name which is pretty interesting. However their tabview function event handler seem to be interesting, but for some reason I can't get them working fine with my specific application.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Original Poster
Rep:
I just noticed that I had done exact same thing previously and it is working fine with Internet Explorer.I have something like this in my page:
PHP Code:
onclick='show_comment({$game_id});'
I believe the only difference between this page and my current page is in their document type. The page that is working fine with onclick event has the following structure:
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Original Poster
Rep:
Alright, after playing around with my code I just realized that it has nothing to do with the document type. I just created an anchor element in a new empty xhtml file and called the function and it worked in FF and Opera. I guess it should be working in IE, too. I don't have IE to test with right now. The other day when I checked IE and Opera, I realized that they have the same behavior to this event.
Then I did exact same thing with my site but it didn't work in it.
After that instead of calling an external function I wrote something like this:
and in my surprise it worked both in Opera and FF. So I copied the javascript function from the external file and placed it at the end of my page inside script tag and called my function again. But, it didn't work either.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Javascript is a hell to debug and developing in Opera and trying to get it to work in IE can double your development times.
I see that in your first example you don't have a semicolon ( after the function call statement. Not sure whether it is required, but IE can be picky.
Next, surround your function call with "Alert()" calls so you know what piece of code is executed. IE skips the entire onclick block if there is just one error in the JS.
Installing a VM is almost a necessity to test you HTML in IE.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Original Poster
Rep:
Thank you. But I realized that when working with xslt, you cannot write a javascript file in an empty file. You have to include your external javascript file inside an xsl file so that you can call functions inside your external javascript. But unfortunately, if you are working with a javascript library like YUI, you cannot use them unless you place all of them in xsl files which doesn't seem to be the best way. I have not figured it out yet how to eliminate that problem.
As you said it's a good practice to include return false; after calling a function.
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 408
Original Poster
Rep:
Thank you. But I realized that when working with xslt, you cannot write a javascript file in an empty file. You have to include your external javascript file inside an xsl file so that you can call functions inside your external javascript. But unfortunately, if you are working with a javascript library like YUI, you cannot use them unless you place all of them in xsl files which doesn't seem to be the best way. I have not figured it out yet how to eliminate that problem.
As you said it's a good practice to include return false; after calling a function.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.