943,649 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
May 1st, 2009
0

Little help, please

Expand 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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
May 1st, 2009
0

Re: Little help, please

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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
May 1st, 2009
0

Re: Little help, please

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>")
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
May 1st, 2009
0

Re: Little help, please

post also the link that will load this file
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
May 1st, 2009
0

Re: Little help, please

Sure, here's the address of this .js file:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. http://atat.ro/js/calendar-ortodox.js
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
May 1st, 2009
0

Re: Little help, please

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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
May 1st, 2009
0

Re: Little help, please

Click to Expand / Collapse  Quote originally posted by wattaman ...
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.
Reputation Points: 21
Solved Threads: 0
Junior Poster
marjan_m is offline Offline
149 posts
since Apr 2005
May 2nd, 2009
0

Re: Little help, please

I have no ideea how to do this.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009
May 2nd, 2009
0

Re: Little help, please

Click to Expand / Collapse  Quote originally posted by wattaman ...
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:

html Syntax (Toggle Plain Text)
  1. <body>
  2. <input type="submit" onclick="test()" />
  3. </body>

If you have any problem then please post your java script code here
Reputation Points: 21
Solved Threads: 0
Junior Poster
marjan_m is offline Offline
149 posts
since Apr 2005
May 2nd, 2009
0

Re: Little help, please

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!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
wattaman is offline Offline
90 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: how to read form element values
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: whew. i dunno what's wrong with my work





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC