Lab: Forms and ValidationIn today's Lab we will be working with forms, and use forms to get information from the user. We will also use functions to validate the form's input. For your reference: Create a simple form and email its dataIn this part, we will create a simple form about flowers. Here is a sample form on flowers. Please don't press the submit button, because it will send an e-mail to Stella's account.We will use a cgi-script eform.cgi, which already exists on puma, to email the contents of a form.
Validate the form's inputIn this part, we want to make sure that the user has typed in a name, before we allow the form data to be sent to your email account. This way we prevent useless email messages (i.e. those without a user name) from being generated and sent by our form. Add a validating function to your HTML document, named validateMyForm().In which part of the document should the function validateMyForm() go? The function should check whether the input box for the user's name is empty. If so, it should produce an alert, with an informative message, and stop the form submission. Otherwise an alert is produced, thanking the user, and the submission goes ahead. Does the function need any input parameters? Does it return a value? If yes, what is the meaning of the value? Now call the validateMyForm() function. On which event(s) can we call our function? Choose one of these events and add the function call. Add to the formNow add a Select Input to your form, to specify a menu of several flowers (roses, carnations, etc) for the user to choose from. Make its default value to be a message, something like "Please choose your favorite flower".Add to your validateMyForm() function the needed Javascript to make sure the user selects something from the Select Input before you allow submission of the form. When you are done, add a radio button to let the user click "Yes" or "No" to answer the question "Do you like flowers?". Make sure that the user cannot choose both "Yes" and "No" at the same time (Hint: what should the names of the buttons be?). Add code to validateMyForm() function to check that the user has selected the answer. Formatting the email messageIf you have time, you can try to format the email message generated by the cgi-script. For that you will have to:
Introduction | Syllabus | Assignments | Documentation | Project |