Is it possible to include one JavaScript file in another JavaScript file like you can do with the php include() function? If this isn't possible, can/how can you have multiple onclick functions in one statement?
My ongoing projects...
www.naturesmagazine.com
www.energyreform.org *new domain*
www.photographyavenue.com
----
You may also remember me as imnewtophp...
Comments
Just thinking maybe theres a way of including many actions in one statement, rather than trying:-
onclick (doaction1)
onclick (doaction2)
try:-
onclick (doaction1, doaction2)
This would basically entail creating another <script> include by editing the page with one JavaScript file so that the second is included when needed.
http://www.phpied.com/javascript-include/ has a basic run down of how to do this with the DOM and other methods, but since the DOM is preferred, I'll go over that in more detail.
Code: First line: Set up a variable that'll direct the script to where it needs to write the new include (in the head section) by the tag name, which is "head".
Line 2: Create a new script tag element as a variable so that you can edit it before outputting it to the page.
Lines 3 & 4: Set attributes for the element (the first part is the attibute and the second part is the value).
Line 5: Same as above, but this is where the file you're including comes in by making use of the function attribute.
Line 6: Basically, this just goes ahead and adds the new element so that we can use it.
Line 7: Returns 0, meaning not true.
If you need to execute multiple javascript functions at once via onclick, you can do this by separating them with a semicolon such as:
[html]
<a href="#" onclick="functionone('params'); functiontwo('params')">This</a>[/html]
Current project: CMS Object.
Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
Release date: NEVER!!!
I wanted to know how to do this so when a user clicked a link, my AJAX would get the necessary information and then display it through a scriptaculous effect. I tried doing this with two onclick elements, but the user would need to click the link twice for each function to occur. Is there any way I could do this?
www.naturesmagazine.com
www.energyreform.org *new domain*
www.photographyavenue.com
----
You may also remember me as imnewtophp...
That code uses Prototype and scriptaculous to fetch the results of a script and to show it using a scriptaculous effect.
Change 'element' to what you want to change (the I.D.), the script to your script that'll pass on the results, the effect to whatever scriptaculous effect you want (there's a lot of them) and duration to however long you feel (in seconds, so the above code is 0.5 seconds).
This doesn't toggle like the other examples I've posted before and yet again, this was written by Rails using it's inbuilt AJAX helpers, not directly by me.
Current project: CMS Object.
Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
Release date: NEVER!!!
www.computerforumz.com
www.naturesmagazine.com
www.energyreform.org *new domain*
www.photographyavenue.com
----
You may also remember me as imnewtophp...
I've done some very small things with it such as a bit of code for a small editor toolbar which forms part of my CMS (admitedly, some of the more complex stuff was borrowed and modified from a free forum script, but this will change).
The thing is that due to being able to program, I can look at what Rails puts out and think "right, so this does this and that does that", meaning I can explain how to edit it to some degree.
All of my AJAX code started with Rails and although you have to put code into Ruby on Rails to get AJAX out, the Ruby you put in is pretty readable.
I really should pick up PHP or Delphi coding again, but I'm busy making Rails my play thing.
I might also take up Django, though I have much less experience with that than with Rails or PHP, and Delphi or Object Pascal as it's more widely know,n, isn't really a web language.
Current project: CMS Object.
Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
Release date: NEVER!!!