Little help, please

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2009
Posts: 18
Reputation: wattaman is an unknown quantity at this point 
Solved Threads: 0
wattaman wattaman is offline Offline
Newbie Poster

Little help, please

 
0
  #1
May 1st, 2009
Hi, all!
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)
  1. <script language="JavaScript" src="/js/ortodox.js" type="text/javascript"></script>
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Little help, please

 
0
  #2
May 1st, 2009
what you want is possible, i demostrate that in following :

your html page content :

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title>Untitled Page</title>
  5. <script type="text/javascript" src="" id="someID"></script>
  6. <script language="javascript" type="text/javascript">
  7. // <!CDATA[
  8.  
  9. function Button2_onclick() {
  10. dosome();
  11. }
  12.  
  13. function Button1_onclick() {
  14. document.getElementById("someID").src = "JScript.js";
  15. }
  16.  
  17. // ]]>
  18. </script>
  19. </head>
  20. <body>
  21. <input id="Button1" type="button" value="button1" onclick="return Button1_onclick()" />
  22. <input id="Button2" type="button" value="button2" onclick="return Button2_onclick()" />
  23.  
  24. </body>
  25. </html>

your JScript.js named javascript file content:

// JScript File

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function dosome()
  2. {
  3. alert("something");
  4. }

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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 18
Reputation: wattaman is an unknown quantity at this point 
Solved Threads: 0
wattaman wattaman is offline Offline
Newbie Poster

Re: Little help, please

 
0
  #3
May 1st, 2009
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var Latime="100%" ;
  2. var Culoaretablou="#e9efff" ;
  3. var Culoarefont="#000080" ;
  4. var Culoarefereastra="#e9efff" ;
  5. var Culoarelink="#6699ff"
  6. time=new Date();
  7. var Luna=time.getMonth() + 1;
  8. var Zi=time.getDate();
  9. var Zi_Nume = time.getDay();
  10. var Zia=time.getDate();
  11. var Zia_Nume = time.getDay();
  12. Zi_Num = Zi
  13. Zia_Nume = Zia
  14. Luna_Nume = Luna
  15. Luna_Audio = Luna
  16. Luna += ""
  17. Zi += ""
  18. Zia += ""
  19. if (Luna.length != 2) Luna = "0" + Luna
  20. if (Zi.length != 2) Zi = "0" + Zi
  21. function MakeArray(n)
  22. {
  23. this.length=n
  24. return this
  25. }
  26. ZiNume=new Array ("Duminica","Luni","Marti","Miercuri","Joi","Vineri","Sâmbata")
  27. LunaNume=new Array (" ","ianuarie","februarie","martie","aprilie","mai","iunie","iulie","august","septembrie","octombrie","noiembrie","decembrie")
  28. LunaAudio=new Array (" ","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
  29. var Sus = "<TABLE cellspacing=0 cellpadding=1 border=0 width=" + Latime + " bgcolor='" + Culoaretablou + "'><TR><TD>"
  30. Latime = Latime -4
  31. Sus += "<TABLE cellspacing=0 cellpadding=1 border=0><TR><TD width='100%' bgcolor='" + Culoaretablou + "'>"
  32. Sus += "<font color='" + Culoarefont + "'><u>Calendar Ortodox: "
  33. Sus += ZiNume[Zi_Nume] + ", " + Zi_Num + " " + LunaNume[Luna_Nume]
  34. Sus += "</u></font>"
  35. Sus += "</TD></TR><TR><TD bgcolor='" + Culoarefereastra + "'>"
  36. var Jos = "</TD></TR><TR><TD align='center' bgcolor='" + Culoaretablou + "'>"
  37. Jos += "</TD></TR></TABLE></TD></TR></TABLE>"
  38. var Link1 = ""
  39. var Link2 = ""
  40. document.write("<script language='JavaSc" + "ript' src='http://www.calendar-ortodox.ro/java/sfintii_zilei/" + LunaNume[Luna_Nume] + "/" + Zi + Luna + ".js'></sc" + "ript>")
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Little help, please

 
0
  #4
May 1st, 2009
post also the link that will load this file
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 18
Reputation: wattaman is an unknown quantity at this point 
Solved Threads: 0
wattaman wattaman is offline Offline
Newbie Poster

Re: Little help, please

 
0
  #5
May 1st, 2009
Sure, here's the address of this .js file:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. http://atat.ro/js/calendar-ortodox.js
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Little help, please

 
0
  #6
May 1st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 149
Reputation: marjan_m is an unknown quantity at this point 
Solved Threads: 0
marjan_m marjan_m is offline Offline
Junior Poster

Re: Little help, please

 
0
  #7
May 1st, 2009
Originally Posted by wattaman View Post
Hi, all!
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)
  1. <script language="JavaScript" src="/js/ortodox.js" type="text/javascript"></script>
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?
Make a function in that js file and put all the code of js in the function. Call that function on onclick event of any link or button.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 18
Reputation: wattaman is an unknown quantity at this point 
Solved Threads: 0
wattaman wattaman is offline Offline
Newbie Poster

Re: Little help, please

 
0
  #8
May 2nd, 2009
I have no ideea how to do this.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 149
Reputation: marjan_m is an unknown quantity at this point 
Solved Threads: 0
marjan_m marjan_m is offline Offline
Junior Poster

Re: Little help, please

 
0
  #9
May 2nd, 2009
Originally Posted by wattaman View Post
I have no ideea how to do this.
It can be done as:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <head>
  2. <script language="javascript" type="text/javascript">
  3. function test()
  4. {
  5. // write ur code here
  6.  
  7. }
  8. </script>
  9. </head>

And the html code will be:

  1. <body>
  2. <input type="submit" onclick="test()" />
  3. </body>

If you have any problem then please post your java script code here
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 18
Reputation: wattaman is an unknown quantity at this point 
Solved Threads: 0
wattaman wattaman is offline Offline
Newbie Poster

Re: Little help, please

 
0
  #10
May 2nd, 2009
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="javascript" type="text/javascript">
  2. function calendar()
  3. {
  4. document.write("<script language='JavaSc" + "ript' src='http://atat.ro/js/calendar-ortodox.js'></sc" + "ript>")
  5. }
  6. </script>
  7. <input type="submit" onclick="calendar()" value="Calendar Ortodox" name="Calendar" />
... 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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC