JavaScript, Lesson 7 - HomeworkQ1The following diagram shows a form which asks the user for certain details. The symbol (*) indicates an entry which must be completed (i.e. the program processing the form should refuse to accept a form where any of these fields is blank). Recreate this form using HTML and connect it to a program which checks to ensure that the required fields contain some sort of data. (You may want to use a table to line the elements of the form correctly). Q2Write a program that implements a form containing two text elements and a button. When the user has entered some text in both elements, clicking on the button will swap the two pieces of text. If either of the text elements is empty then clicking on the button should produce an error message. Q3You have already seen that the document.write() method can be used to write HTML tags on the screen. Use this method to get a JavaScript program to create a form on the screen, together with its own JavaScript event handler! (The form doesn't have to be a very complicated one!) Q4Create a web page that consists of a hyperlink, whose caption is "Please do not click on this link". When the user clicks on the link (as will inevitably happen!) the web page should display the message "I told you not to click on the link!" Q5In section 3, you were asked to write a program that asked the user for the three sides of a triangle and then displayed its perimeter. Rewrite that program so that it uses text elements rather than the prompt() instruction. Q6Write a simple quiz program that asks the user 10 general knowledge questions (such as "What is the capital of France?") using forms and a button at the end to submit the answers. Clicking on the answers displays a score at the end. |