Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Declaring global variables in JavaScript

From: Set a Marquee to Autoplay with jQuery and Dreamweaver

Video: Declaring global variables in JavaScript

Now that we're ready to modify the JavaScript file from the previous course, let's open up the marquee.js in Dreamweaver or switch over to that open tab. And before the (document).ready in this particular script, where we actually setup the marquee, let's hit a few Returns and let's set up the five variables that we need to access to make the autoplay function properly. So this is the global area inside of the JavaScript. We're going to start by typing var for variable. I'm going to start by typing currentPanel. We're going to set this equal to 1.

Declaring global variables in JavaScript

Now that we're ready to modify the JavaScript file from the previous course, let's open up the marquee.js in Dreamweaver or switch over to that open tab. And before the (document).ready in this particular script, where we actually setup the marquee, let's hit a few Returns and let's set up the five variables that we need to access to make the autoplay function properly. So this is the global area inside of the JavaScript. We're going to start by typing var for variable. I'm going to start by typing currentPanel. We're going to set this equal to 1.

Next we're going to type variable totalPanels. We're going to set this equal to zero to start and then we'll have our jQuery actually generate the total number of panels by modifying the script below. Next we're going to set autoPlay. We're going to set this equal to True. Next we'll set timePassed. we'll set that equal to zero as well.

Next we'll type variable timeToChange. We're going to set this to 3. This is going to be three seconds, so that the marquee will play every three seconds. This will be too fast for our end project, but we wanted to set something quick while we're testing and debugging this so we can actually make sure that it plays properly and it doesn't take a lot of time to play through. Now inside of the (document).ready, we want to set up a few statements here that will send these variables over to the HTML page. These are going to be part of our debugging scripts. So I'm going to type a forward slash and an asterisk, type debug and then asterisk and forward slash. This is going to put a small comment in the beginning of this line.

And I'm going to put this debug comment before every time we send data over to the HTML, so that we can go back later and be able to remove these. So I'm going to start by typing a dollar sign, beginning and ending parenthesis. Inside of the parentheses we'll type two tick marks. I'm going to type autoPlay and this is the autoPlay class from the debug area in the HTML, not the variable that we have set up above here.

So we're going to set the autoPlay div, html, beginning and ending parentheses, semicolon, and then inside of the html we're going to put two ticks for a string literal, and then we're going to type autoPlay, which is just text, equals, space, and then I get the cursor outside of the tick mark, but before the ending parentheses, hit a plus sign, and now we need to access the global variables inside of this JavaScript. We are running inside of the function here, so in order to go out and get that global variable we're going to type window.autoPlay.

Again, by typing window here we can go out to the global script area. Now that we have the first debug statement set up, let's copy this. Command+C or Ctrl+C to copy. We're going to paste two, three more of these to give ourselves a total of four. We have five of them up here, but we're going to set the total panels a little bit later. So now Dreamweaver gives us a really nice way to select variable names and class names and element names. I'm going to come up here. I want to set the timePassed variable, it being the second one.

So I can come up here, double- click on timePassed, and then it will automatically select that item. Command+C or Ctrl+C to copy. Let's come down in the debug line here. Double-click on autoPlay. It will automatically highlight. I can hit Paste. I can double-click autoPlay here which is a string literal, and double-click autoPlay here which is a JavaScript variable. So this gives me again a really quick way to cut and paste the different values. Next, let's come up here and double-click timeToChange. Copy that. Let's paste that into the third spot and then let's come up and double-click currentPanel.

Let's come down and paste currentPanel on the fourth item here. At this point let's choose File > Save. So now at the beginning of the document we have our global five variables set up. We're going to set the state of these variables to debug in the HTML when we load the page. And in the next movie we're going to modify the existing script to get the total panels and the actual current panel based on the navigational item that was clicked.

Show transcript

This video is part of

Image for Set a Marquee to Autoplay with jQuery and Dreamweaver
 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Set a Marquee to Autoplay with jQuery and Dreamweaver.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.