2 times onclick
- Started
- Last post
- 17 Responses
- janne76
hi, i have 2 different javascripts that need to respond to the same ID once it is clicked. now only one script works and the other one works only when i deactivate the other script.
what to do?
one is an ajax request (works!), the other collapses the nav (not working with ajax one).
any ideas?
ps. i am not a pro at js but learning more everday.
- welded0
You'll need to link to the code - could be any number of things.
- heavyt0
i am guessing that you have two places in code where the onclick event is assigned to that ID. The second one will then cannibalize the first.
easiest thing is to have one function call the other one. So, your ajax function for instance would call the function for the collapse in it.function ajaxthing(){
...;
collapseDiv();
}
- janne760
code is here, don't mind the design, it's rough now..
http://mediatorsaanzee.nl/test/m…
ajax bit is after the collapse script...
- janne760
i still need to learn so much javascript but very little time available!
any books/tuts are welcome!
- janne760
i have no idea how to merge those functions.. :(
- amullins0
the line that is NOT executing is
if(clickedArticle && clickedArticle!=this)clickedArti...
i set a breakpoint @ that line and clickedArticle appears to be false
- janne760
and what now?
- amullins0
you may try setting the default value for clickedArticle to true instead of false, just to see if this fixes the issue.
- acescence0
so, the ajax stuff is working, but your jquery stuff has stopped working? i think the issue is that the window.onload handler may be stomping on jquery. i would try to unify all of your js into one block, and put everything that needs to fire on page load into a jquery $(document).ready() function. as it is, i can't quite figure out how the jquery stuff would be working at all on its own, as you are missing this critical part.
- janne760
nice, i think i solved. ajax now calling the LI tag and other script only A tag.
next problem is how to figure out to load the right doc's from the links in the submenu when collapsed. now they only load the parent.. :/
thx for the help so far! :D
- flashbender0
you need to improve your subject naming skills. This should have been called
2 times 1 click
- janne760
ah i found the best ajax tutorial ever, jquery based....
and it is SOLVED!
http://mediatorsaanzee.nl/test/t…
here's the tut:
http://nettuts.com/javascript-aj…do get the adjusted script from the comments here, to enable the BACKbutton (yes! :))
http://nettuts.com/javascript-aj…and if you use .php extension instead of .html change
window.location.hash = $(this).attr('href').substr(0...
to THIS:
window.location.hash = $(this).attr('href').substr(0...even the Google Analytics issue with AJAX is solved here:
http://nettuts.com/javascript-aj…the good thing is, you can get to the content in different ways, so bookmarking is no issue, neither is providing a direct link to the page as a whole (the php in this case):
http://mediatorsaanzee.nl/test/t…
http://mediatorsaanzee.nl/test/t…
= same contentlovely! :D
- janne760
this went wrong
---
and if you use .php extension instead of .html change
window.location.hash = $(this).attr('href').substr(0...
to THIS:
window.location.hash = $(this).attr('href').substr(0...
--go here instead, see his reaction to Jay:
- janne760
i expected so much more..
i am really felling james1000'ish now..
:(