The form of <form> |
Last time, we saw JS put text (4) in the source file before finishing the page | |
Now we see JS | |
create buttons | |
and windows, | |
and manipulate | |
data in the finished | |
page |
Input & Output in JS are given in forms | |||
Inside <form> tags | |||
Notice | |||
type | |||
value | |||
relationship to text |
Notice | |||
type | |||
name | |||
size | |||
relationship to text |
Notice | |||
type | |||
name (common) | |||
relationship to text |
Windows are input or output based on your point of view … | |||
Programming uses computer’s view | |||
It’s obvious that buttons are inputs | |||
Windows are inputs, but if the computer puts information in them, they’re outputs | |||
After drawing a page, browsers sit idle waiting for something to happen … when we give input, it cause events | |||
Processing the input is the task of an event handler | |||
Event types | |||
onClick | |||
onChange | |||
onMouseOver |
Event handlers say what | ||
to do if event happens … | ||
“put ‘Smiley’ in the output | ||
window” |
Notice … | |||
‘onClick’ event does | |||
the task: place ‘Smiley’ | |||
in the output window | |||
Notice … | |||
the value of a text | |||
window is the contents | |||
of the window | |||
x.value |
Notice | |||
names | |||
+ is concatenate |
Conditionals test if an expression is true or not | |||
General form … | |||
if (<Boolean expression>) | |||
<Then statement>; | |||
For example | |||
if (day == "Friday") | |||
evening_plan = "party"; |
Branch both ways with If-Then-Else | |||
if (<Boolean expression>) | |||
<Then statement>; | |||
else | |||
<Else Statement>; | |||
Example … if ((year%4)== 0) { | |||
leapYear = true; | |||
febDays = febDays+1; | |||
} | |||
else | |||
leapYear = false; |