Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was.

Similar presentations


Presentation on theme: "JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was."— Presentation transcript:

1 JavaScript, Third Edition 1 SELECTION LIST Demo

2 JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was chosen. If not, the an alert box will be displayed, otherwise the form will be submitted. This demo shows the following: –The proper coding of the tag –The proper coding of the formfield (in this case, the button) –The capturing of the submit buttons click event –The definition of a function –The execution of the function

3 JavaScript, Third Edition 3 <!-- HTML COMMENT WILL HIDE FROM INCOMPATIBLE BROWSERS function editFormData() { } // STOP HIDING FROM INCOMPATIBLE BROWSERS --> Create the structural code for the function inside the script tag. Name the function :

4 JavaScript, Third Edition 4 function editFormData() { if (document.forms[0].lstPet.selectedIndex < 1) { window.alert("Please check which pet you would like to have!") return false; } else { if (document.forms[0].lstPet.options[1].selected == true) { window.alert ("You have a dog!"); return true; } else { window.alert ("You have a cat!"); return true; } The logic in the function to verify a selection was made

5 JavaScript, Third Edition 5 <!-- HTML COMMENT WILL HIDE FROM INCOMPATIBLE BROWSERS function editFormData () { ….. // STOP HIDING FROM INCOMPATIBLE BROWSERS --> Add an HTML form tag pair the web page.

6 JavaScript, Third Edition 6 <!-- HTML COMMENT WILL HIDE FROM INCOMPATIBLE BROWSERS function editFormData () { … } // STOP HIDING FROM INCOMPATIBLE BROWSERS --> Pick your pet Select a Pet Dog Cat Add an HTML SUBMIT button to the web page. When its onclick event occurs, execute the function editFormData()

7 JavaScript, Third Edition 7 How it works… From formProcessor.html when form is submitted If cat selected If dog selected

8 JavaScript, Third Edition 8 CODE Select function editFormData() { if (document.forms[0].lstPet.selectedIndex == 0) { alert("Please check which pet you have or would like to have!") return false; } else { if (document.forms[0].lstPet.options[1].selected == true) { alert ("You have a dog!"); return true; } else { alert ("You have a cat!"); return true; } CONTINUED ON NEXT SLIDE

9 JavaScript, Third Edition 9 CODE Editing a Select Pick your pet Select a Pet Dog Cat


Download ppt "JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was."

Similar presentations


Ads by Google