JavaScript Onload Code

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

ZafarAbidAsked:
Who is Participating?
 
-null-Connect With a Mentor Commented:
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
 
ZafarAbidAuthor Commented:
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
 
ZafarAbidAuthor Commented:
Thank you. :)
0
 
-null-Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.