☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

The AND gate on a web page

الأسبوع 10 · الوحدة ٢ الموضوع الثالث: محاكاة بوابة AND كصفحة ويب بلغة PHP: التصميم والكود وشرحه والحالات الأربع · 3 دروس
1

The AND gate on a web page: two lists and a button

ICT Secondary 3 Term 1, Unit 2, Topic 3: pp. 32–39
GoalDescribe the AND page: two drop-down lists, an Apply button and a lamp, and say how it differs from the VB.NET window.
New words
drop-down list · a control that shows a list of choices and lets the visitor pick oneoption · one choice inside a listvalue · the text that is sent to the server when that option is chosenApply button · the submit button that sends both choices to the page
Explanation

In Week 9 each switch was a button that flipped when clicked. A web page does not flip in place without more code, so the page uses two drop-down lists, one for each switch, with the options on and off, and an Apply button. The visitor picks the two states and presses Apply; the page comes back and says whether the lamp is lit. The page is a form, as in Week 7. Each list has a name, list1 and list2, so that PHP can find what was chosen. Each option has a value, and the value is what travels to the server; the words between the tags are only what the visitor reads. Two small rules of HTML: always give every option a value, and write a space between attributes. In our version the lamp is a line of text that PHP fills in; the original project shows a lit-lamp or unlit-lamp picture chosen in the same way.

Window (Week 9)Page (this week)
a switcha button that flipsa drop-down list: on or off
what starts the worka click on a switchthe Apply button sends the form
the lampa box that changes coloura line of text that PHP fills in
Worked examples
Html
1<form method="post">
2  <select name="list1">
3    <option value="off">off</option>
4    <option value="on">on</option>
5  </select>
6  <select name="list2">
7    <option value="off">off</option>
8    <option value="on">on</option>
9  </select>
10  <input type="submit" name="apply" value="Apply">
11</form>
12<p>The lamp is <?php echo $lamp; ?>.</p>
The form and the place of the lamp, in HTML. PHP will fill $lamp.
NameValue sent
list1on
list2off
applyApply
What travels to the server when the visitor chooses on in the first list, off in the second, and presses Apply. PHP finds each value by its name.
Before Apply is pressed nothing is sent, so on the first visit the form’s values do not exist yet. The page must handle that case too, and the next lesson shows how.
Class activity

Design on paper an AND page whose lamp is lit when a key list says turned and a button list says pressed. Write the options of each list with their values, give the lists names, and say which values PHP receives for the choice turned and pressed.

Practice
1
What does the value of an option do?
2
Which controls does the page have?
3
How does PHP find what was chosen in a list?
4
Why does the Apply button have a name?