ncthakur.itgo.com   Javascript: If & Else Statement

         NEPAL     |     ARTICLES     |     KAVITAHARU    |     MANTHAN    |     COOL LINKS    |     GUESTBOOK    |     SEARCH

JAVASCRIPT
As I have learned as a beginner:
1. Opening New Window

2. Use of Alert, Prompt & Confirm

3. Document Write

4. Use of Function

5. Event Handlers (Image Rollover)

6. If and Else Statement

7. Predefined Object (Date)

8. Cut & Paste JavaScript

NEPAL
Overview of Nepal
Map & images
Nepalese websites

KAVITAHARU
View few of my poems
written in Nepali language

ARTICLES
Articles on
crime prevention
investigation
& crime control

COOL LINKS
Computer
Travel & Tour
Police World
Downloads
Personality Test
Nepal News
Crime & Police News
Nepali Music
Health
Horoscope
Monthly Poll
Other

ADD EMAIL
Search or add email to the search list.

GUESTBOOK
View to find out what other visitors have to say about this web site.

KURAKANI
Are you interested to chat? Go to Kurakani room.

FREE E-CARDS
Enormous free E-Cards of your choice. Send it to your friend and family members.

FREE SITE SUBMIT
Submit your web site to the major search engines here.

ABOUT ME
Click here to find out about me and view few of my photographs.

 

If and Else Statement

if and else statement is used to make something happen in a given condition, else to happen something else in another condition. var is variable used to define an object. nct1 is a prompt, which asks if you like apple or javascript. nct2 is "You are wonderful". If your answer to nct1 is apple, it will write You are wonderful, you like to eat fruits;-; else in case of your answer as javascript, it will write You are intelligent, you can learn javascript easily

<script language="JavaScript>
<--hide from older browser
var nct1= prompt("Do you like apple or javascript?")
var nct2="You are wonderful"
var nct3="You are intelligent"
if (nct1=="apple")
{
document.write(nct2+", you like to eat fruits!");
}
else
if (nct1=="javascript"){
document.write(nct3+", you can learn JavaScript easily");
}
//--> </script>

The use of two = sign in if (nct1= ="apple") is to tell the JavaScript that nct1 may or may not be equal to apple. It could be equal to javascript too as in (nct1= ="javascript"). Using only one = sign will tell the JavaScript that nct2 must be equal to "You are wonderful".

It is good to keep in mind that MSIE (Microsoft Internet Explorer) and NS (Netscape Navigator) browsers behave differently while interpreting JavaScript Codes, and it is always wise to use cross-browser codes that works well with both the browsers or to have two different web pages for different browsers.
For Example
<script language="JavaScript">
<!-- hide
if (navigator.appName == "Netscape")
window.location="your01.htm"
else
window.location="your02.htm"
}
//-->
</script>

If you are using a Netscape browser it will load your01.htm page otherwise if you are using a MSIE or other browser, it will load your02.htm page. In my example if you are using Netscape you will be viewing my javascript page js02.htm otherwise, javascript page js05.htm will be loaded for MSIE or other browser.

BACK

NEXT..........


Top

Home  | About Me  |  Nepal  |  Articles  | Kavitaharu  | Cool Links 
 Javascript  | Add Email  |  Guestbook