EVILSOFTS...
Would you like to react to this message? Create an account in a few clicks or log in to continue.


TOTALLY EVILINSIDEZZ...
 
HomeLatest imagesSearchRegisterLog in

 

 Tutorial - IF .. . Then

Go down 
2 posters
AuthorMessage
devendra
developer
developer



Posts : 3
Join date : 2010-09-21

Tutorial - IF  .. . Then       Empty
PostSubject: Tutorial - IF .. . Then    Tutorial - IF  .. . Then       Icon_minitimeThu Sep 23, 2010 4:11 am

The if-then statement.
OK, once again, here is the entire code. Give it a look, then we'll break it down. This is a good example of an If-Then statement. Password scripts can also be combined with an encryption function so that hackers can't break in simply by viewing your source code. The purpose of this chapter, however, is to give you some practice with if-then statements.



--------------------------------------------------------------------------------

<HTML>
<HEAD>
<TITLE>Chapter 3, If-then statements</TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

function password() {


Ret = prompt('Type the word castle',"");
if(Ret=="castle") {

location = 'ch03_1.htm';

} else {

alert("Please try again")

}

}
// - End of JavaScript - -->
</SCRIPT>

</HEAD>
<BODY>

<A HREF="javascript:password()">
<IMG SRC="pict1.gif" NAME="pic1" ALT="about us!" BORDER="0" align="left"></A>

<H3>Click the image to enter a password protected document. Try a wrong entry first.</H3>

</BODY>
</HTML>



BREAK DOWN OF CODE

function password() {

Ret = prompt('Type the word castle',"");
if(Ret=="castle") {

location = 'ch03_1.html';


--------------------------------------------------------------------------------

The prompt

The first line of the function, password() is:


Ret = prompt('Type the word castle',"");
This command tells the computer to open a prompt box, and assign whatever the user types to the variable, Ret. Therefore if the user types "chickensoup", the computer will execute the command
Ret="chickensoup"

I can then compare the variable Ret with other text to determine if the user typed in the correct password.

The parentheses contain the message inside the prompt box, then the default text. Look at this sample command, then click the show me button

prompt("Please type your name","Newt")



If you do not want a default, simply place 2 quotes after the comma like I did in the original example






if(Ret=="castle") {

location = 'ch03_1.html';

} else {

alert("Please try again")

}


--------------------------------------------------------------------------------

The if-then statement

The second line of the function is an if-then statement. It tells the computer that if the variable Ret equals "castle" then change the URL location to ch03_1.html. Otherwise, show the alert box which says "Please try again."

Here is the format of an if-then statement:
IF (a comparison)

{ sequence if the comparison is true }

ELSE { sequence is the comparison is false }


For example, let's say you've just had the reader complete a form which included their age. You want all Senior Citizens to get one message, and everyone else to get another when they submit the form.

age=form.age.value transfer the contents of the age box on the form to a variable called age.
if (age>=65) The if statement begins with the question in parentheses.
{alert("Your form has been submitted. Ask about our Senior Discounts") } The alert box will be displayed if the question is true, age IS greater or equal to 65
ELSE {alert("Your form has been submitted.") } The alert box command following the word ELSE will only be displayed if the question is false, and age IS NOT greater or equal to 65.

Back to top Go down
Admin
Admin
Admin
Admin


Posts : 44
Join date : 2010-09-20
Age : 34
Location : mumbai

Tutorial - IF  .. . Then       Empty
PostSubject: Re: Tutorial - IF .. . Then    Tutorial - IF  .. . Then       Icon_minitimeThu Sep 23, 2010 9:33 am

nyc share devendra Very Happy keep sharing more...but if its tutorial then post it in tutorial section Twisted Evil thanks for sharing such nyc scripts..keep sharing Basketball



Tutorial - IF  .. . Then       Glitte10
Back to top Go down
https://evilsofts.forumotion.com
 
Tutorial - IF .. . Then
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
EVILSOFTS... :: DEVELOPING TOOLS-
Jump to: