conditions and more web form fields

22
Conditions and More Web Form Fields

Upload: aidan-patel

Post on 31-Dec-2015

23 views

Category:

Documents


2 download

DESCRIPTION

Conditions and More Web Form Fields. Conditions. if (then) else Syntax. if. (. ). Boolean expression. {. instructions if expression is true (then). }. else. {. instructions if expression is false. }. Example. Check age. < 59. >=59 and 65. Gotta Work!. Early Retirement?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Conditions and More Web Form Fields

Conditions and More Web Form Fields

Page 2: Conditions and More Web Form Fields

Conditions

Page 3: Conditions and More Web Form Fields

if (then) else Syntax

if ( )Boolean expression

{

{

}

}

instructions if expression is true (then)

instructions if expression is false

else

Page 4: Conditions and More Web Form Fields

Example

Check age

< 59 >65

Gotta Work! Retire!

>=59 and <65

Early Retirement?

Page 5: Conditions and More Web Form Fields

Example – Step 1if ( )age < 59{

}alert(‘Gotta Work!’)

Page 6: Conditions and More Web Form Fields

Example – Step 2if ( )age < 59{

{

}

}alert(‘Gotta Work!’)

else

{

}alert(‘Early Retirement?’)

if ( )age >= 59 && age < 65(age >= 59) && (age < 65)

Page 7: Conditions and More Web Form Fields

Example – Step 2 (v2)if ( )age < 59{

}alert(‘Gotta Work!’)

elseif ( )(age >= 59) && (age < 65){

}alert(‘Early Retirement?’)

Page 8: Conditions and More Web Form Fields

Example – Step 3if ( )age < 59{

}alert(‘Gotta Work!’)

elseif ( )(age >= 59) && (age < 65){

}alert(‘Early Retirement?’)

else{

}alert(‘Retire!’)

Page 9: Conditions and More Web Form Fields

Example – Step 3 (v2)if ( )age < 59{

}alert(‘Gotta Work!’)

elseif ( )(age >= 59) && (age < 65){

}alert(‘Early Retirement?’)

else{

}alert(‘Retire!’)

Page 10: Conditions and More Web Form Fields

Relational Operators

== Equal to

> Greater than

< Less than

>= Greater than or equal to

<= Less than or equal to

!= Not equal to

Page 11: Conditions and More Web Form Fields

Danger Will Robinsonfunction check(p){

var a = palert('initial a = ' + a)if (a = 5){

alert('if a = 5')}alert('final a = ' + a)

}

check(10)initial a = 10

if a = 5final a = 5

a == 5JavaScript assignment statements execute and evaluate to true.

Page 12: Conditions and More Web Form Fields

Expressions and Conditions

if ( )(age >= 59) && (age < 65)

Boolean Expression

Condition 1 Condition 2

Page 13: Conditions and More Web Form Fields

AND and OR

AND &&Both conditions true expression is true.Otherwise expression is false.

if (condition1 && condition2)

OR ||Either condition true expression is true.

if (condition1 || condition2)

Page 14: Conditions and More Web Form Fields

More Web Form Fields

Page 15: Conditions and More Web Form Fields

Checkbox

<input type="checkbox" name="student" checked="checked" />

Page 16: Conditions and More Web Form Fields

Checkbox

document.getstuff.student.checked

. . .document form field checked

Booleantrue orfalse

Page 17: Conditions and More Web Form Fields

Radio Button

<input type="radio" name="sex" Id="female"value="F" />

<input type="radio" name="sex" id="male"value="M" />

Gender:Male <input type="radio" name="sex" id="male" value="M" /> Female <input type="radio" name="sex" id="female" value="F" />

Index = 0

Index = 1

Page 18: Conditions and More Web Form Fields

var messagevar indx

message = ‘by Index using Checked property\n‘

for (indx = 0; indx < document.getstuff.sex.length; indx++){

message = message + 'Indx=' + indx + ' checked=' + document.getstuff.sex[indx].checked + '\n‘

}

alert(message)

Page 19: Conditions and More Web Form Fields

message = ‘by Index using Value property\n‘

for (indx = 0; indx < document.getstuff.sex.length; indx++){

message = message + 'Indx=' + indx + ' value=' + document.getstuff.sex[indx].value + '\n‘

}

alert(message)

Page 20: Conditions and More Web Form Fields

message = ‘by d.f.id.checked\n‘

message = message + 'document.getstuff.male.checked=' + document.getstuff.male.checked + '\n‘

message = message + 'document.getstuff.female.checked=' + document.getstuff.female.checked + '\n‘

alert(message)

Page 21: Conditions and More Web Form Fields

Select and Option

<select name="major"><option value="mis">Management Information Systems</option><option value="cis">Computer Information Systems</option><option value="isp">Information Security and Privacy</option>

</select>

Page 22: Conditions and More Web Form Fields

Select and Option

document.getstuff.major.value

. .document form field value.

<select name="major"><option value="mis">Management Information Systems</option><option value="cis">Computer Information Systems</option><option value="isp">Information Security and Privacy</option>

</select>