0% found this document useful (0 votes)
12 views

Script March2017

This document contains JavaScript code to validate form input fields. The code checks if the first name, surname, and telephone number fields are empty and displays an alert if they are. It also checks if the num field value is less than 1 or greater than 10, and displays an alert if so. The code uses the document.form1 object to reference the form fields and validate the values when a validation function is called.
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
12 views

Script March2017

This document contains JavaScript code to validate form input fields. The code checks if the first name, surname, and telephone number fields are empty and displays an alert if they are. It also checks if the num field value is less than 1 or greater than 10, and displays an alert if so. The code uses the document.form1 object to reference the form fields and validate the values when a validation function is called.
Copyright
© © All Rights Reserved
You are on page 1/ 1

JavaScripting June 2017 P4

Solution

<script>

function validate()
{
if(document.form1.forename.value=="")
{
alert("Please enter your first name")
}
if(document.form1.surname.value=="")
{
alert("Please enter your surname")
}
if(document.form1.telno.value=="")
{
alert("Please enter your telephone number")
}
if((document.form1.num.value<1) || (document.form1.num.value>10))
{
alert("Please enter a value between 1 to 10")
}
}

</script>

You might also like