JavaScript programming, Lecture notes of Programming Languages

Web development with javascript

Typology: Lecture notes

2021/2022

Uploaded on 01/04/2025

philip-obara
philip-obara 🇰🇪

8 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Unit 20: Client side customisation of web pages
JavaScript Activity 1
The purpose of this lab session is to use JavaScript within an XHTML page.
This exercise will set up the page so that a welcome message is posted when
the page is first loaded, then when the form submit button is clicked, it will
undertake some very basic form data existence validation.
1. Create a theatre booking form html page. (Like the one below)
2. Refer to the lecture notes and write the code that will show an alert box
with a welcome message when the page is loaded. (Hint: you will need
to set the onload event in the Body tag).
3. Test this within a browser to make sure it works.
4. Add the code to do the validation for the text boxes on the form. The
validation will be to make sure that the user enters in a value into the text
boxes. To do this first we need to add the function which will do the
validation as follows into the head section of the HTML page:
<script type="text/javascript">
function checkall(frmEnquiry)
{
if (frmEnquiry.txtName.value == "")
{
alert("You must enter a name");
return (false);
}
}
</script>
Then add the code which will call this function to the form tag as follows:
<form method="post" onsubmit="return checkall(this);"
action="senddetails.asp">
4. Test the code to make sure that the validation works like this:
1
This is the onsubmit
attribute that will call
the function checkall
This is the name of
the form name text
box
pf2

Partial preview of the text

Download JavaScript programming and more Lecture notes Programming Languages in PDF only on Docsity!

Unit 20: Client side customisation of web pages JavaScript Activity 1 The purpose of this lab session is to use JavaScript within an XHTML page. This exercise will set up the page so that a welcome message is posted when the page is first loaded, then when the form submit button is clicked, it will undertake some very basic form data existence validation.

  1. Create a theatre booking form html page. (Like the one below)
  2. Refer to the lecture notes and write the code that will show an alert box with a welcome message when the page is loaded. ( Hint: you will need to set the onload event in the Body tag).
  3. Test this within a browser to make sure it works.
  4. Add the code to do the validation for the text boxes on the form. The validation will be to make sure that the user enters in a value into the text boxes. To do this first we need to add the function which will do the validation as follows into the head section of the HTML page: Then add the code which will call this function to the form tag as follows:
  5. Test the code to make sure that the validation works like this: 1 This is the onsubmit attribute that will call the function checkall This is the name of the form name text box

Unit 20: Client side customisation of web pages

  1. Amend the code so that it also does the existence validation for both the email and phone text boxes additionally.
  2. Using the isNaN(frmEnquiry.txtPhone.value) function described in the lecture add the validation to check additionally to see whether the value entered into txtPhone is a number (hint you will need to use || (this is the OR operator)).
  3. Add the validation so that the email address contains an ‘@’ somewhere after the second character (look that the lecture notes if you need help). NOTE: JavaScript is case sensitive
  4. Validate your work and create a word document to show the validation results. You should also include the URL of your .html page in the word document. Extension Exercise: As part of the new legal requirement of alerting users that cookies will be used on your web page can you please create a pop up dialogue box containing instructions as to the use of cookies on the website. Please research the relevant information to give display to the user. 2