Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conditions and More Web Form Fields. Conditions if (then) else Syntax if( ) Boolean expression { { } } instructions if expression is true (then) instructions.

Similar presentations


Presentation on theme: "Conditions and More Web Form Fields. Conditions if (then) else Syntax if( ) Boolean expression { { } } instructions if expression is true (then) instructions."— Presentation transcript:

1 Conditions and More Web Form Fields

2 Conditions

3 if (then) else Syntax if( ) Boolean expression { { } } instructions if expression is true (then) instructions if expression is false else

4 Example Check age < 59 >65 Gotta Work!Retire! >=59 and <65 Early Retirement?

5 Example – Step 1 if()age < 59 { } alert(‘Gotta Work!’)

6 Example – Step 2 if()age < 59 { { } } alert(‘Gotta Work!’) else { } alert(‘Early Retirement?’) if()age >= 59 && age < 65 (age >= 59) && (age < 65)

7 Example – Step 2 (v2) if()age < 59 { } alert(‘Gotta Work!’) else if()(age >= 59) && (age < 65) { } alert(‘Early Retirement?’)

8 Example – Step 3 if()age < 59 { } alert(‘Gotta Work!’) else if()(age >= 59) && (age < 65) { } alert(‘Early Retirement?’) else { } alert(‘Retire!’)

9 Example – Step 3 (v2) if()age < 59 { } alert(‘Gotta Work!’) else if()(age >= 59) && (age < 65) { } alert(‘Early Retirement?’) else { } alert(‘Retire!’)

10 Relational Operators == Equal to >Greater than <Less than >=Greater than or equal to <=Less than or equal to !=Not equal to

11 Danger Will Robinson function check(p) { var a = p alert('initial a = ' + a) if (a = 5) { alert('if a = 5') } alert('final a = ' + a) } check(10) initial a = 10 if a = 5 final a = 5 a == 5 JavaScript assignment statements execute and evaluate to true.

12 Expressions and Conditions if()(age >= 59) && (age < 65) Boolean Expression Condition 1Condition 2

13 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)

14 More Web Form Fields

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

16 Checkbox document.getstuff.student.checked...documentformfieldchecked Boolean true or false

17 Radio Button <input type="radio" name="sex" Id="female" value="F" /> <input type="radio" name="sex" id="male" value="M" /> Gender: Male Female Index = 0 Index = 1

18 var message var 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)

19 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)

20 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)

21 Select and Option Management Information Systems Computer Information Systems Information Security and Privacy

22 Select and Option document.getstuff.major.value..documentformfieldvalue. Management Information Systems Computer Information Systems Information Security and Privacy


Download ppt "Conditions and More Web Form Fields. Conditions if (then) else Syntax if( ) Boolean expression { { } } instructions if expression is true (then) instructions."

Similar presentations


Ads by Google