| | |
Little help, please
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 18
Reputation:
Solved Threads: 0
Hi, all!
I have a problem I hope someone smarter then me will fix
So, I'm integrating a javascript in my site:
as you can see, is in a separate .js file. The site loads too slow, because of this.
What I'd like to do is to load the javascript only when the vizitor click a particular link. I don't know if is possible, though.
Also, I found many onclick link codes that show the content of a particular hidden div or table (or whatever). However, what I don't know is: if I put the code above in a hidden div, will it still load and slow the site or it will load when the div is displayed?
I have a problem I hope someone smarter then me will fix

So, I'm integrating a javascript in my site:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript" src="/js/ortodox.js" type="text/javascript"></script>
What I'd like to do is to load the javascript only when the vizitor click a particular link. I don't know if is possible, though.
Also, I found many onclick link codes that show the content of a particular hidden div or table (or whatever). However, what I don't know is: if I put the code above in a hidden div, will it still load and slow the site or it will load when the div is displayed?
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
what you want is possible, i demostrate that in following :
your html page content :
your JScript.js named javascript file content:
// JScript File
when you directly click button2, you will get error stating that function not found. if you click button 1 first, it will load the javascript file dynamically, then if you click button 1 you will see the message box.
your html page content :
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <script type="text/javascript" src="" id="someID"></script> <script language="javascript" type="text/javascript"> // <!CDATA[ function Button2_onclick() { dosome(); } function Button1_onclick() { document.getElementById("someID").src = "JScript.js"; } // ]]> </script> </head> <body> <input id="Button1" type="button" value="button1" onclick="return Button1_onclick()" /> <input id="Button2" type="button" value="button2" onclick="return Button2_onclick()" /> </body> </html>
your JScript.js named javascript file content:
// JScript File
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function dosome() { alert("something"); }
when you directly click button2, you will get error stating that function not found. if you click button 1 first, it will load the javascript file dynamically, then if you click button 1 you will see the message box.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: May 2009
Posts: 18
Reputation:
Solved Threads: 0
Thanks, it doesn't work.
Maybe the .js content matters?! If so, the .js file I want to load/display when the button is clicked is this:
Maybe the .js content matters?! If so, the .js file I want to load/display when the button is clicked is this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var Latime="100%" ; var Culoaretablou="#e9efff" ; var Culoarefont="#000080" ; var Culoarefereastra="#e9efff" ; var Culoarelink="#6699ff" time=new Date(); var Luna=time.getMonth() + 1; var Zi=time.getDate(); var Zi_Nume = time.getDay(); var Zia=time.getDate(); var Zia_Nume = time.getDay(); Zi_Num = Zi Zia_Nume = Zia Luna_Nume = Luna Luna_Audio = Luna Luna += "" Zi += "" Zia += "" if (Luna.length != 2) Luna = "0" + Luna if (Zi.length != 2) Zi = "0" + Zi function MakeArray(n) { this.length=n return this } ZiNume=new Array ("Duminica","Luni","Marti","Miercuri","Joi","Vineri","Sâmbata") LunaNume=new Array (" ","ianuarie","februarie","martie","aprilie","mai","iunie","iulie","august","septembrie","octombrie","noiembrie","decembrie") LunaAudio=new Array (" ","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec") var Sus = "<TABLE cellspacing=0 cellpadding=1 border=0 width=" + Latime + " bgcolor='" + Culoaretablou + "'><TR><TD>" Latime = Latime -4 Sus += "<TABLE cellspacing=0 cellpadding=1 border=0><TR><TD width='100%' bgcolor='" + Culoaretablou + "'>" Sus += "<font color='" + Culoarefont + "'><u>Calendar Ortodox: " Sus += ZiNume[Zi_Nume] + ", " + Zi_Num + " " + LunaNume[Luna_Nume] Sus += "</u></font>" Sus += "</TD></TR><TR><TD bgcolor='" + Culoarefereastra + "'>" var Jos = "</TD></TR><TR><TD align='center' bgcolor='" + Culoaretablou + "'>" Jos += "</TD></TR></TABLE></TD></TR></TABLE>" var Link1 = "" var Link2 = "" document.write("<script language='JavaSc" + "ript' src='http://www.calendar-ortodox.ro/java/sfintii_zilei/" + LunaNume[Luna_Nume] + "/" + Zi + Luna + ".js'></sc" + "ript>")
•
•
Join Date: May 2009
Posts: 18
Reputation:
Solved Threads: 0
Sure, here's the address of this .js file:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
http://atat.ro/js/calendar-ortodox.js
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
look i dont think it is a good idea to load the file after the link clicked, it may still take long and it can call the function before the load completes in which case you are going to get object not found error. so i think let it be slow.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Apr 2005
Posts: 149
Reputation:
Solved Threads: 0
•
•
•
•
Hi, all!
I have a problem I hope someone smarter then me will fix
So, I'm integrating a javascript in my site:
as you can see, is in a separate .js file. The site loads too slow, because of this.JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript" src="/js/ortodox.js" type="text/javascript"></script>
What I'd like to do is to load the javascript only when the vizitor click a particular link. I don't know if is possible, though.
Also, I found many onclick link codes that show the content of a particular hidden div or table (or whatever). However, what I don't know is: if I put the code above in a hidden div, will it still load and slow the site or it will load when the div is displayed?
•
•
Join Date: Apr 2005
Posts: 149
Reputation:
Solved Threads: 0
It can be done as:
And the html code will be:
If you have any problem then please post your java script code here
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<head> <script language="javascript" type="text/javascript"> function test() { // write ur code here } </script> </head>
And the html code will be:
html Syntax (Toggle Plain Text)
<body> <input type="submit" onclick="test()" /> </body>
If you have any problem then please post your java script code here
•
•
Join Date: May 2009
Posts: 18
Reputation:
Solved Threads: 0
Thanks, m8. I almost got it working. So, first of all if I put the .js code in the function it doesn't load the script - just keeps loading forever.
So, tooking your suggestion, I'm using this code instead:
... which works, kin of... It loads the script in a new browser window.
Can I make it load under the button, on the same page, I mean? I want the button to show on all pages and the script to load, also, on the site's pages.
BTW, here it is http://atat.ro , upper-right column, just above the social bookmark icons.
Thanks again!
So, tooking your suggestion, I'm using this code instead:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="javascript" type="text/javascript"> function calendar() { document.write("<script language='JavaSc" + "ript' src='http://atat.ro/js/calendar-ortodox.js'></sc" + "ript>") } </script> <input type="submit" onclick="calendar()" value="Calendar Ortodox" name="Calendar" />
Can I make it load under the button, on the same page, I mean? I want the button to show on all pages and the script to load, also, on the site's pages.
BTW, here it is http://atat.ro , upper-right column, just above the social bookmark icons.
Thanks again!
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: how to read form element values
- Next Thread: whew. i dunno what's wrong with my work
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically browser bug calendar captchaformproblem cart checkbox child class close codes createrange() cursor date debugger dependent disablefirebug dom dropdown editor element embed engine events explorer ext file firefox form forms getselection google gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump libcurl maps masterpage math media microsoft object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post programming progressbar prototype redirect regex runtime safari scale scriptlets scroll search security shopping size software sql text textarea toggle unicode web website windowsxp wysiwyg \n






