iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning JavaScript Course: Variables and Conditions - www.itechcollege.com JavaScript Course: Variables and Conditions - www.itechcollege.com
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

courses > JavaScript > Variables and Conditions

Variables and Conditions

Let's see an example:

     <script>
     var x=window.confirm("Are you 
	 sure you want to quit");
     if (x)
     window.alert("Thank you.");
     else
     window.alert("Good choice.");
     </script>

There are several concepts that we should know. First of all, "var x=" is a variable declaration. If you want to create a variable, you must declare the variable using the var statement. x will get the result, namely, "true" or "false". Then we use a condition statement "if else" to give the script the ability to choose between two paths, depending on this result (condition for the following action). If the result is true (the user clicked "ok"), "Thank you" is alerted. If the result is false (the user clicked "cancel"), "Good choice" is alerted instead. So we can make more complex boxes using "var", "if" and those basic methods.

     <script>
     var y=window.prompt("please enter your name")
     window.alert(y)
     </script>

Another example:

     <html><head>
     <script>
     var x=confirm("Are you sure you want to quit?");
     if (!x)
     window.location="http://www.onlineschoolnet.com";
     </script>
     </head>
     <body>
     Welcome to my website!.
     </body></html>

If click "cancel", it will take you to onlineschoolnet.com, and clicking ok will continue with the loading of the current page "Welcome to my website!". Note:if (!x)means: if click "cancel". In JavaScript, the exclamation mark (!) means: "none".



  Back to Index Page
 Next Page:  

Embedding and including
write and writeln
Document object
Message box
Variables and Conditions
Function
Event handler
Form
Link
Date
Window
Frame


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech