We help IT Professionals succeed at work.

JavaScript Onload Code

ZafarAbid
ZafarAbid asked
on
Medium Priority
254 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

Comment
Watch Question

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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

Author

Commented:
Thank you. :)

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.