?
Solved

JavaScript Onload Code

Posted on 2009-02-17
4
Medium Priority
?
245 Views
Last Modified: 2012-05-06
Hi,
I am using ASP for a page, where I load a list of videos from db... listing of videos and when you click them, they play properly but the first video does not load automatically... I want to load the first video from db when the page loads in the browser for the first time.

I have pasted the code below, I hope this helps you understand my question.

Regards,
Zafar
Code Chunk 1:
////////////////////////
<li style="margin-right:0px; padding-right:0px; margin-bottom:0px; padding-bottom:0px; "  >
 
<A id="vlist<%=cnt%>" HREF="#" STYLE="text-decoration:none; padding-right:0px; margin-right:0px;  " onclick='javascript:new_video(s1,"<%=vid_url%>","<%=RS2("VIDEO_TITLE")%>","<%=RS2("VIDEO_DESCRIPTION")%>",<%=cnt%>)' onMouseOver="this.style.cursor='hand';vidOn(<%=cnt%>);" onmouseout="vidOff(<%=cnt%>);" ><%=RS2("VIDEO_TITLE")%>
</A>
</li>
///////////////////////////////////
 
The function: Code Chunk 2:
///////////////////////////////////
function new_video(s1,vid_name,vid_title,vid_des,vlist) {
	s1.addVariable("FlashVars","&bgColor=0xFFFFFF&serverName=NAME_OF_THE_SERVER" + vid_name);
	s1.write("player1");
 
    if (crtList != 0) {
    	document.getElementById("vlist" + crtList).style.backgroundColor = "#E2E2E2";
    }
    crtList = vlist;
    if (crtList != 0) {
    	document.getElementById("vlist" + crtList).style.backgroundColor = "#D4D4D4";
    }
}
///////////////////////////////////

Open in new window

0
Comment
Question by:ZafarAbid
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
-null- earned 1000 total points
ID: 23667986
Hi

You could put your onclick event code into the body's onload event attribute for the first video.  When the page first loads, and finishes creating the DOM, it will simulate clicking the first video entry.  Swap the text values out in the string below.

-null-
onload='javascript:new_video(s1,"first_video_url","first_video_title","first_video_description",1)'

Open in new window

0
 

Author Comment

by:ZafarAbid
ID: 23676249
I totally agree with your solution and it worked as well... one more concern is that the body tag is at the top and the SQL query and db opening is in an include file...

Do you suggest moving all that code at the top? or how should I deal with this situation?

Regards,
Zafar
0
 

Author Closing Comment

by:ZafarAbid
ID: 31548160
Thank you. :)
0
 
LVL 5

Expert Comment

by:-null-
ID: 23679904
You can treat the sql and db code as being seperate to the body of the document. You shouldn't have to move it.

null
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question