1 / 22

Conditions and More Web Form Fields

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. >65. Gotta Work!. Early Retirement?.

aidan-patel
Download Presentation

Conditions and More Web Form Fields

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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) } else { instructions if expression is false }

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

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

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

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

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

  9. if ( age < 59 ) if ( (age >= 59) && (age < 65) ) Example – Step 3 (v2) { alert(‘Gotta Work!’) } else { 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) } a == 5 JavaScript assignment statements execute and evaluate to true. check(10) initial a = 10 if a = 5 final a = 5

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

  13. AND and OR AND && if (condition1 && condition2) Both conditions true  expression is true. Otherwise expression is false. OR || if (condition1 || condition2) Either condition true  expression is true.

  14. More Web Form Fields

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

  16. Checkbox document . form . field . checked document.getstuff.student.checked Boolean true or false

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

  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 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> Select and Option

  22. Select and Option document . form . field . value document.getstuff.major.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>

More Related