Conditions and More Web Form Fields
Conditions
if (then) else Syntax if( ) Boolean expression { { } } instructions if expression is true (then) instructions if expression is false else
Example Check age < 59 >65 Gotta Work!Retire! >=59 and <65 Early Retirement?
Example – Step 1 if()age < 59 { } alert(‘Gotta Work!’)
Example – Step 2 if()age < 59 { { } } alert(‘Gotta Work!’) else { } alert(‘Early Retirement?’) if()age >= 59 && age < 65 (age >= 59) && (age < 65)
Example – Step 2 (v2) if()age < 59 { } alert(‘Gotta Work!’) else if()(age >= 59) && (age < 65) { } alert(‘Early Retirement?’)
Example – Step 3 if()age < 59 { } alert(‘Gotta Work!’) else if()(age >= 59) && (age < 65) { } alert(‘Early Retirement?’) else { } alert(‘Retire!’)
Example – Step 3 (v2) if()age < 59 { } alert(‘Gotta Work!’) else if()(age >= 59) && (age < 65) { } alert(‘Early Retirement?’) else { } alert(‘Retire!’)
Relational Operators == Equal to >Greater than <Less than >=Greater than or equal to <=Less than or equal to !=Not equal to
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.
Expressions and Conditions if()(age >= 59) && (age < 65) Boolean Expression Condition 1Condition 2
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)
More Web Form Fields
Checkbox <input type="checkbox" name="student" checked="checked" />
Checkbox document.getstuff.student.checked...documentformfieldchecked Boolean true or false
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
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)
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)
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)
Select and Option Management Information Systems Computer Information Systems Information Security and Privacy
Select and Option document.getstuff.major.value..documentformfieldvalue. Management Information Systems Computer Information Systems Information Security and Privacy