JavaScript Onload Code

Posted on 2009-02-17
Last Modified: 2012-05-06
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.

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="'hand';vidOn(<%=cnt%>);" onmouseout="vidOff(<%=cnt%>);" ><%=RS2("VIDEO_TITLE")%>




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);


    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

Question by:ZafarAbid
    LVL 5

    Accepted Solution


    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.


    Open in new window


    Author Comment

    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?


    Author Closing Comment

    Thank you. :)
    LVL 5

    Expert Comment

    You can treat the sql and db code as being seperate to the body of the document. You shouldn't have to move it.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    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…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now