Question
Forms and Form Elements Forms as Objects A form is an object so if you want to refer to it in JavaScript, it should be
Forms and Form Elements
Forms as Objects
- A form is an object so if you want to refer to it in JavaScript, it should be given a name.
- An example of how to name a form and then to refer to it in JavaScript is shown:
Example 2 onChange, onFocus and onBlur Event Handlers
function upperMe() {
document.trialForm.converter.value = document.trialForm.converter.value.toUpperCase()
}
function focusAlert() {
alert("You just entered the second text field")
}
function blurAlert() {
alert("You just left the second text field")
}
Using onChange, onFocus, and onBlur.
Button Objects
- The only really useful JavaScripting for buttons is the onClick event handler (we already used this in the previous lesson).
Checkbox Objects
- Checkboxes can be either checked or not. This means the key property is the checked property.
- This can be used in an ifelse statement which will return true if checked and false if not.
Example 3 checked Property
function inspectBox() {
if (thisForm.checkThis.checked) {
alert("The box is checked.")
} else {
alert("The box is not checked at the moment.")
}
}
Assignment #7
- Rewrite Example 1 (the password verification program) so that if the passwords dont match, both password fields will be cleared and the cursor will be returned to the first password field. Also, have the alert boxes include the name entered in the first field (i.e. ______, you must enter a password. or ______, your entered passwords did not match). Make sure to change all your variable names, form name, etc. to match what you are doing in your assignment. Save the file as "7a_forms.html" in your shared OneDrive folder.
- Make a form that has a two text fields. However, the first text field is a trick text field. Every time you try putting the cursor in the first field, an alert box will pop up that says Ha! Ha! and the cursor goes over to the second text field. In other words, there is no way to enter any text in the first text box. Make sure to change all your variable names, form name, etc. to match what you are doing in your assignment. Save the file as "7b_forms.html" in your shared OneDrive folder.
- Make a form with a checkbox and a button. Whenever the button is clicked, the checkbox will become checked and then unchecked if the button is clicked again. (Hint: use the click() method for checkboxes in order to do this). Make sure to change all your variable names, form name, etc. to match what you are doing in your assignment. Save the file as "7c_forms.html" in your shared OneDrive folder.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started